Date and Time Values
MS-Access have Date/Time Data Field Type to store Date or Time or both Date and Time together. When you enter a Date Value into the Field (such as 14/07/2010) the actual value stored in memory is a whole number 40373, the number of days from 30-12-1899. Day 1 is 31-12-1899.
You can easily find this if you type ? format(1,"dd/mm/yyyy") in the Debug Window (Alt+F11 to display VBA Editing Window and Ctrl+G to show Debug Window) and pressing Enter Key to show the result value 31-12-1899.
Like Date; Time is internally stored as a Decimal Number. Time at midnight is 0.0 and 0.5 at 12 Noon. So the Date and Time Value combined on 14th July 2010 at 12 Noon is 40373.5.
To find the difference in time between Midnight and a time value before that, the midnight value will be taken as 24.00 for calculation purposes instead of 0.00.
Type ? format(40373.5,"dd/mm/yyyy hh:nn:ss") and press Enter Key.
Result: 14/07/2010 12:00:00
It is interesting to explore as how 0.5 becomes 12:00:00 noon or how the System maintains Date and Time internally?
We know we have 24 Hours in a Day or 24 x 60 = 1440 minutes in a Day or 24 x 60 x 60 = 86400 Seconds in a Day.
That is 1 Second = 1 Day/86400 Seconds = 0.000011574074074074 Day (we can take it rounded as 0.0000115741). The end value 074 is infinite.
From Midnight the Value 0.0000115741 (equal to one Second) is added to the Time of the Day Value at every one Second interval. One Second before midnight (23:59:59 Hrs.) the value is 0.9999906659 (86399 Seconds) and after one second; a Day is added to the Date Value. So at Midnight of 14/07/2010 the Number of Days become 40374.
But, each Second is further divided into Milliseconds and this can be read with the use of Timer Built-in Function.
For example type the following direct command in the Debug Window:
You will get the output something like the example given below depending on the time you try out this.
Result in Seconds: 68473.81
The Value .81 part is the time in milliseconds and 68473 the number of seconds of the current time of the day.
If you want to see this value in Current Time of the Day format type the following expression in Debug Window and press Enter Key:
The Value of 68473.81 Seconds are converted into its equal value in Days by multiplying it with 0.0000115741.
You can use the Timer() Function to build a delay loop in Program, like the example given below, to slow down some action in Programs.
Public Function myFunction() . . . t = Timer Do While Timer < t + 0.5 DoEvents Loop . . . End Function
The sample program segment above slows down the action by one half of a Second before executing the next statement after the Loop statement.
We can get the current Date and Time Value from the System with the use of Now() Built-in Function. The Date() Function returns the Current System Date.
While designing a Table you can set the Default Value Property of the Date/Time Field to Date() Function or Now() Function to insert Current System Date or Current Date and Time Stamp respectively, when a new record is added to the Table.