FORMATDATETIME

FORMATDATETIME(date [,namedformat])

Returns the expression formatted as a date or time (String).


dateThe date to be formatted (Variant).
namedformat(Optional) A vbDateTimeFormat constant that specifies the format (Integer):
0 = vbGeneralDate (default)
1 = vbLongDate
2 = vbShortDate
3 = vbLongTime
4 = vbShortTime

REMARKS
* If "namedformat" is left blank, then 0 is used.
* This function was added in VB 6.0 and is slightly faster than using FORMAT
* You can use the FORMAT function to return a text string of a date in a particular format.
* You can use the FORMATCURRENCY function to return an expression formatted as a currency value.
* You can use the FORMATNUMBER function to return an expression formatted as a number.
* You can use the FORMATPERCENT function to return an expression formatted as a percentage.
* The equivalent .NET function is [[Microsoft.VisualBasic.Strings.FormatDateTime]]
* For the Microsoft documentation refer to learn.microsoft.com

Debug.Print FormatDateTime(Date + TimeValue("04:30:00"), VbDateTimeFormat.vbGeneralDate) '= 18/02/2024 04:30:00  
Debug.Print FormatDateTime(Date + Time(), VbDateTimeFormat.vbLongDate) '= 18 February 2024
Debug.Print FormatDateTime(Date, VbDateTimeFormat.vbLongDate) '= 18 February 2024
Debug.Print FormatDateTime(Date, VbDateTimeFormat.vbShortDate) '= 18/02/2024
Debug.Print FormatDateTime(Date + Time(), VbDateTimeFormat.vbLongTime) '= 09:24:53
Debug.Print FormatDateTime(Time(), VbDateTimeFormat.vbLongTime) '= 09:24:53
Debug.Print FormatDateTime(Time(), VbDateTimeFormat.vbShortTime) '= 09:24

Dim dtDate As Date
dtDate = #1/7/2024#
Debug.Print FormatDateTime(dtDate, vbGeneralDate) '= 07/01/2024
Debug.Print FormatDateTime(dtDate, vbLongDate) '= 07 January 2024
Debug.Print FormatDateTime(dtDate, vbShortDate) '= 07/01/2024

dtDate = #1/7/2024 12:30:20 PM#
Debug.Print FormatDateTime(dtDate, vbLongTime) '= 12:30:20
Debug.Print FormatDateTime(dtDate, vbShortTime) '= 12:30

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