How do I convert a date to text in Access XP

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
If you want to add the time up to seconds then

=cstr(format([MyDate],"ddmmyyyyhhmmss")
 
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
 
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
 
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
 
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
 
Back
Top