Changing Data format

S

Sam

I have a text field in a table for a data and time - the time is
importing as 9/5/2006 11:54:03:257.

I need to have the data formated as MM/DD/YYYY, using the example
above the date/time of 9/5/2006 11:54:03:257 should be 09/05/2006.

Please help with a formula to change this date with in a query.

thanks
 
D

Duane Hookom

You should try the DateValue() function:
RealDate: DateValue([text field in a table for a data and time])
 
J

John Spencer

DateValue will error with a string like "9/5/2006 11:54:03:257"

You have to remove the last 4 characters (assumption being that the
milliseconds are always expressed as three digits) or just grab the date portion.

DateValue(Left([DateString],Len([DateString])-4))

or

DateValue(Left([DateString],Instr(1,[DateString]," ")-1))

If Datestring is null or zero-length or cannot be interpreted as a date, you
will get an error.

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

Hans Up

Sam said:
I have a text field in a table for a data and time - the time is
importing as 9/5/2006 11:54:03:257.

I need to have the data formated as MM/DD/YYYY, using the example
above the date/time of 9/5/2006 11:54:03:257 should be 09/05/2006.

My guess is that you intend 09/05/2006 to remain a text value, instead
of converting it to date data type. Let us know if I guessed wrong.
Please help with a formula to change this date with in a query.

Replace YDT with the name of your field which contains the date text values:

FormattedDate: Format(Left([YDT],Instr(1,[YDT]," ")-1),"mm/dd/yyyy")
 

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

Similar Threads


Top