Date/time formatting

  • Thread starter Thread starter Liam
  • Start date Start date
L

Liam

I want to store my time information in a Date/Time field
in a table.

My input data is 6 numbers:
year, month, day, hour, minute and second.

How do I get that converted to a value, I can save in a
Date/Time field?
 
Access will do that for you. Just type it in in the normal date/time
format. Let Access worry about how it is stored.

Rick B
 
OK - and what is then "the normal date/time format"?

It should be a format that is not affecetd by th eregional
settings.
 
OK - and what is then "the normal date/time format"?

It should be a format that is not affecetd by th eregional
settings.

Access will make *reasonable* interpretations of anything that looks
like a puncutated date. For instance, if the user types

15 Dec 2004 11:01:20am

the result will be stored correctly.

The one "gotcha" is that ambiguous day-month entries such as 3/8/2004
(is this March 8, American style, or 3 August, European style?) will
depend on the regional settings. If you want complete control over
this, you can use six numeric textboxes txtYear, txtMonth, txtDay,
txtHour, txtMinute, and txtSecond and use

DateSerial(txtYear, txtMonth, txtDay) + TimeSerial(txtHour, txtMinute,
txtSecond)

to calculate the date/time value unambiguously (assuming that the user
puts the right number in the right textbox!)


John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
If you've actually got the values as six different numbers, you can use the
DateSerial and TimeSerial functions. Assuming the values are stored in
lngYear, lngMonth, lngDay, lngHour, lngMinute and lngSecond, the timestamp
corresponding to that would be

DateSerial(lngYear, lngMonth, lngDay) + TimeSerial(lngHour, lngMinute,
lngSecond)
 
Back
Top