Date Literals

Date literals can be enclosed within number signs (#) when using the "Date" data type.
Although when assigning a date to a Date variable this can also be done in a string format (eg Noon = #12:00:00# or #1/12/2002#. StartTime = Now().
When assigning a date to a date variable you can also use a valid date string format.
For example the following are all valid

Dim dtMyDate As Date 
dtMyDate = #1/2/07#
dtMyDate = #7/7/06#
dtMyDate = #12:50:00 AM#
dtMyDate = "January 15, 2008"
dtMyDate = "2/7/06 12:55:00 PM"

You can also use double quotation marks but this is not very common and takes slightly longer to run

dtMyDate = ""7/7/06"" 

American Format

In VBA dates and times are enclosed between two hash (#) signs, for example:

Dim dtExpiries As Date 
dtExpiries = #12/31/2006# 'this is interpreted as m/d/yyyy by default - check !!!
dtExpiries = #31/12/2006#
dtExpiries = "December 31, 2006"
dtExpiries = #01:30:00 AM#
dtExpiries = #31/12/06 07:30:00 PM#

VBA will automatically adjust the date if it is entered in the "dd/mm/yyyy" format to "mm/dd/yyyy".

dtExpiries = #31/12/2006# 'automatically changed from #12/31/2006#  

VBA will also automatically adjust the time into AM/PM notation if it is entered in 24hr notation.

dtExpiries = #07:30:00 PM# 'automatically changed from #19:30:00#  


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext