Introduction
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 press 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 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.
Time Calculations
That is 1 Second = 1 Day/86400 Seconds = 0.000011574074074074 Day (we can take it rounded as 0.0000115741). The end value of 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:
? Timer
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:
? format(68473.81/86400,"hh:nn:ss")
OR
? format(68473.81*0.0000115741,"hh:nn:ss")
The Value of 68473.81 Seconds is converted into its equal value in Days by multiplying it with 0.0000115741.
Result: 19:01:14
Using the Timer Function.
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 + 5 DoEvents Loop . . . End Function
The sample program segment above slows down the action by 5 Seconds 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.
- Microsoft Date/Time Picker Control
- Form and Report Open Arguments
- Indexing and sorting with VBA
- Data Upload Controls
- Auto Numbering in Query Column
[...] Quarter:GetQrtr(Month([Visit Date])) Find out how date and time values are stored internally from here. __________________ http://www.msaccesstips.com (Learn MS-Access Tips and Tricks) Learn [...]
ReplyDeleteConverting Date information currently in a text file in YYYY-MM-DD format into an MS-Access compatible date format MM/DD/YYYY.
ReplyDeleteDoes anyone have a suggestion on how to do this?
Example:
ReplyDeleteDt = "2020-10-31"
? DateValue(Dt)
Result: 31-10-2020
OR
x = dateserial(left(dt,4),mid(dt,6,2),right(dt,2))
? x
Result: 31-10-2020
Change the Regional Settings of Windows Date/Time Format to change the result in American Date Format: 10-31-2020