View Full Version : custom date/time format


purple curtain
06-24-2003, 07:31 AM
I am relatively inexperienced in Access, and am trying to set the default value for a field in a table as the current date (British format, DD/MM/YY) plus the current time. Having tried and failed with "Date() And Time()", I'd be grateful if anyone could help.

FoFa
06-24-2003, 07:35 AM
A date column will hold that, but it is in Access format (basically I think a long integer). The format comes into play once you extract the date. You can put date and time in with now(). If your regional settings are set to UK, does not Access display it in UK format for you? You could always hard code the format for display using format(mydate,"dd/MM/yyyy hh:mm:ss") as an example.

purple curtain
06-24-2003, 07:38 AM
Thanks for your reply. Access does show Now() in British format, but only locally. I'm using it on a website, and it shows up as US format when used online. How would I add hard code?

Pat Hartman
06-24-2003, 09:27 AM
If you want the default value of a field to be the current date and time, use Now(). All date datatype fields are a format that Microsoft calls a serial number. The integer portion of the number represents the number of days since Dec 30, 1899 and the decimal portion is the number of miliseconds since midnight. So - 6/24/2003 12:22:10 PM = 37796.5153935185.

How a date is formatted for display is up to your application. Windows allows you to set a default date/time display format. That is what is used unless your application overrides the default by specifying a different format.

As you can see, by storing a date/time value as a double precision number, Microsoft avoids all confusion as to format and simplifies many internal date calculations.