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

Comments are subject to moderation before publishing.

Translate



PageRank
Subscribe in a reader
Your email address:

Delivered by FeedBurner

http://clicky.com/101199826
Blog Directory Visit blogadda.com to discover Indian blogs

Search

Popular Posts

Search This Blog

Blog Archive

Powered by Blogger.

Follow by Email

Labels

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

Featured Post

WithEvents and All Form Control Types

Introduction So far we have worked extensively with only one type of Control: the TextBoxes on Form, enabled with Events to Raise and captur...

Labels

Blog Archive

Recent Posts