Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / March 2006

Tip: Looking for answers? Try searching our database.

Converting a YYYYMMDD field into 3 fields YYYY MM and DD

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tim Whitley - 14 Mar 2006 17:16 GMT
Is there a way that I can modify the data as it is brought into the query to
create 3 fields with the YYYY MM and DD vs 1 field with YYYYMMDD?
Wayne Morgan - 14 Mar 2006 18:12 GMT
You will find dates easier to work with if you leave them as date data types
and just format them as needed when you need something different.

Where is this value coming from? You state that it is "brought into the
query". If it is an Access table, is the data type of the field set to
Date/Time?

Regardless of the above, eventually you'll need to create 3 calculated
fields for the query to do what you're asking. The calculation is what will
vary, depending on what the value really is (a number as a text string or a
date data type).

To create a calculated field, open the query in design view. In the field
box, type the name you would like for the calculated field (don't use a
reserved word such as Date, Month, Year, etc). Follow this by a Colon and
then the calculation.

Example:
MonthFromDate:Format([DateField], "mm")
or
MonthFromDate:Month([DateField])

The second one will drop the leading zero if you're always wanting 2 digits.
The examples are based on the value being a Date/Time data type. If it is
just a string of numbers, you'll have to break the string apart. If it is
always 8 characters, this is fairly simple.

Example:
MonthFromDate:Mid([DateField], 5, 2)
DayFromDate:Right([DateField],2)
YearFromDate:Left([DateField],4)

Signature

Wayne Morgan
MS Access MVP

> Is there a way that I can modify the data as it is brought into the query
> to
> create 3 fields with the YYYY MM and DD vs 1 field with YYYYMMDD?
Tim Whitley - 14 Mar 2006 21:20 GMT
This worked like a charm.  FYI...the data is being pulled from a ODBC
connection to a legacy system.  As such, I believe that the date data is
formatted as text.

> You will find dates easier to work with if you leave them as date data types
> and just format them as needed when you need something different.
[quoted text clipped - 31 lines]
> > to
> > create 3 fields with the YYYY MM and DD vs 1 field with YYYYMMDD?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.