DATE - Function

DATE()

Returns the current system date (Variant / Date).


REMARKS
* The default format is "dd/mm/yyyy" (or "mm/dd/yyyy" in the US).
* When this is used in the VBA Editor the brackets are automatically removed.
* This function should be prefixed with "VBA." to make it easier to understand.
* You can use the DATE Statement to set the current system date.
* You can use the DATEADD to return the date with a specified time interval added.
* You can use the DATEDIFF function to return the number of a given time interval between two specified dates.
* You can use the DATEPART function to return the specified part of a given date.
* You can use the DATESERIAL function to return the date given a year, month and day.
* You can use the DATEVALUE function to return the date given a string representation of a date.
* You can use the DATE$ function to return a String data type instead of a Variant data type.
* You can use the FORMAT function to return a text string of a date in a particular format.
* You can use the NOW function to return the current system date and time.
* You can use the TIME function to return the current system time.
* For the Microsoft documentation refer to learn.microsoft.com

Debug.Print VBA.Date()                                              '= volatile  
Debug.Print VBA.Format(VBA.Date(), "dd mmm yyyy hh:mm:ss") '= "18 Feb 2024 00:00:00"
Debug.Print VBA.Format(VBA.Date() + Time(), "dd mmm yyyy hh:mm:ss") '= "18 Feb 2024 12:15:59"

Dim lSerial As Long
lSerial = VBA.Date()
Debug.Print lSerial '= 45340

Dim sDate As String
sDate = VBA.Date()
Debug.Print sDate '= 18/02/2024

Dim dtDate As Date
dtDate = VBA.Date()
Debug.Print dtDate '= 18/02/2024

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