dbTalk Databases Forums  

using query to format date

comp.database.ms-access comp.database.ms-access


Discuss using query to format date in the comp.database.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Larry Rekow
 
Posts: n/a

Default using query to format date - 05-11-2004 , 03:19 PM






I have a text table i'm linking to in an access d/b. the date is
displayed as 20040511
for May 11, 2004

I'd like to use an expression in a query to display this as 5/11/04

but after some research and googling i'm coming up empty.

anyone have the answer to this and perhaps a page of date examples?

thanks.
- - - - - - - - - - - - - - - - - -
"Forget it, Jake. It's Chinatown."

Reply With Quote
  #2  
Old   
Koyan
 
Posts: n/a

Default Re: using query to format date - 05-12-2004 , 03:00 AM






Larry Rekow wrote:
Quote:
I have a text table i'm linking to in an access d/b. the date is
displayed as 20040511
for May 11, 2004

I'd like to use an expression in a query to display this as 5/11/04

but after some research and googling i'm coming up empty.

anyone have the answer to this and perhaps a page of date examples?
Assuming that your table is called "table1" and your field is called
"stringdate", you can use the following SQL to understand the normal how
you can make the normal date:

SELECT stringdate, Left([stringdate],4) AS year, Mid([stringdate],5,2)
AS Month, Mid([stringdate],7,2) AS day,
DateSerial(Left([stringdate],4),Mid([stringdate],5,2),Mid([stringdate],7,2))
AS normalDate
FROM Table1;

If you want to make it in code instead of SQL you can do the following:
stringdate = "20040511"
normaldate=
DateSerial(Left(stringdate,4),Mid(stringdate,5,2), Mid(stringdate,7,2)


Hope this helped.
Tell us how it worked for you.




Reply With Quote
  #3  
Old   
Ray
 
Posts: n/a

Default Re: using query to format date - 05-12-2004 , 08:06 AM



Larry Rekow <larry@netgeexdotcom> wrote

Quote:
I have a text table i'm linking to in an access d/b. the date is
displayed as 20040511
for May 11, 2004

I'd like to use an expression in a query to display this as 5/11/04

but after some research and googling i'm coming up empty.

anyone have the answer to this and perhaps a page of date examples?

thanks.
- - - - - - - - - - - - - - - - - -
"Forget it, Jake. It's Chinatown."
Hello Larry,

Look up the Format function in Access help.

Example: Format(MyDate, "mmm d yyyy")' Returns "Jan 27 1993".

A quick note: you might have to split out the data in the field
and combine it back together so that you will display it in the
correct format.

Add these fields into your source query and replace "MyDate"
field with the one your using.

YearDate: Mid([MyDate],1,4)

MonthDate: Mid([MyDate],5,2)

DayDate: Mid([MyDate],7,2)

DateFormated: CDate([MonthDate] & [DayDate] & [YearDate])

NewDateFormat: Format(DateFormated, "mmm d yyyy")

Hope this starts you in the right direction.

Regards,

Ray


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.