Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

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:

? 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*0.0000115741,"hh:nn:ss")

The Value of 68473.81 Seconds are converted into its equal value in Days by multiplying it with 0.0000115741.

Result: 19:01:14

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.

Share:

1 comment:

  1. [...] 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 [...]

    ReplyDelete

Translate



PageRank
Your email address:

Delivered by FeedBurner

Search

Infolinks Text Ads


Blogs Directory

Popular Posts

Search This Blog

Blog Archive

Powered by Blogger.

Labels

Forms How Tos Functions MS-Access Security Reports Animations msaccess animation msaccess forms Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Queries External Links msaccess reports msaccess tips Menus and Toolbars Accesstips MsaccessLinks Process Controls Art Work Downloads msaccess How Tos Graph Charts msaccessQuery List Boxes Command Buttons Emails and Alerts Query Combo Boxes Custom Wizards ms-access functions msaccess graphs msaccess reporttricks msaccessprocess security advanced Access Security DOS Commands Data Macros Menus Property Report Top Values VBA msaccess email msaccess menus progressmeter Access2007 Array Auto-Number Command Button Custom Functions Join Microsoft Numbering System Records Security Split SubForm Table Utility Workgroup database msaccess functions msaccess wizards Access2003 Accounting Year Action Animation Attachment Binary Numbers Budgeting Calculation ChDir Color Palette Conditional Formatting Controls Copy Data Filtering Data Type Defining Pages Diagram Disk Dynamic Lookup Error Handler Excel Export Expression External Field Type Fields Filter Form Form Instances Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Methods Monitoring Object Reference Objects Octal Numbers Operating System Paste Primary-Key Product Rank Reading Rich Text Sequence SetFocus Summary Tab-Page Time Difference Union Query User Users Variables Water-Mark Word automatically commands function hyperlinks iSeries Date iif ms-access msaccess msaccess alerts pdf files reference restore switch text toolbar tutorial updating upload vba code

Featured Post

DIR Getting File Names From Folder

We all know Dir() Function from the time of Windows DOS Operating System.  This is the first Command introduced to those who sit on a Perso...

Labels

Blog Archive

Recent Posts