How do I convert a date to text in Access XP

G

Guest

Can anyone advise the code to use an Access query to convert a date or time
to a string - e.g. 04/07/2005 to 04072005?

Thanks
 
G

Guest

If you want to add the time up to seconds then

=cstr(format([MyDate],"ddmmyyyyhhmmss")
 
J

John Spencer (MVP)

Whoops.

The format character for minutes is "n" not "m" - m is already used for Month,
so some other character has to be used for minutes.

=cstr(format([MyDate],"ddmmyyyyhhnnss")

Also, FYI the format function creates a string, so CStr is not really needed.
If you want to add the time up to seconds then

=cstr(format([MyDate],"ddmmyyyyhhmmss")

Dudley said:
Can anyone advise the code to use an Access query to convert a date or time
to a string - e.g. 04/07/2005 to 04072005?

Thanks
 
G

Guest

Thank you

John Spencer (MVP) said:
Whoops.

The format character for minutes is "n" not "m" - m is already used for Month,
so some other character has to be used for minutes.

=cstr(format([MyDate],"ddmmyyyyhhnnss")

Also, FYI the format function creates a string, so CStr is not really needed.
If you want to add the time up to seconds then

=cstr(format([MyDate],"ddmmyyyyhhmmss")

Dudley said:
Can anyone advise the code to use an Access query to convert a date or time
to a string - e.g. 04/07/2005 to 04072005?

Thanks
 
E

E-mail report using Lotus Notes rather t

Ofer,

You are a god...I can just kiss you man...I been looking for this for a
while...thank you so much dude...



Ofer said:
Try this, convert to string after formating

cstr(format([DateField],"ddmmyyyy")

Dudley said:
Can anyone advise the code to use an Access query to convert a date or time
to a string - e.g. 04/07/2005 to 04072005?

Thanks
 
J

John Spencer

Overkill. Format always returns a string, so there is no need to use CStr

Format(DateField,"ddmmyyyy") will have the same result as
CStr(Format(DateField,"ddmmyyyy"))

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

E-mail report using Lotus Notes rather t said:
Ofer,

You are a god...I can just kiss you man...I been looking for this for a
while...thank you so much dude...



Ofer said:
Try this, convert to string after formating

cstr(format([DateField],"ddmmyyyy")

Dudley said:
Can anyone advise the code to use an Access query to convert a date or time
to a string - e.g. 04/07/2005 to 04072005?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top