FORMATDATETIME(date [,namedformat])

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


dateThe date to be formatted (Date).
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 docs.microsoft.com

Debug.Print FormatDateTime(Date + TimeValue("04:30:00"), VBA.vbDateTimeFormat.vbGeneralDate) = 24/10/2008 04:30:00 
Debug.Print FormatDateTime(Date + Time(), VBA.vbDateTimeFormat.vbLongDate) = 24 October 2008
Debug.Print FormatDateTime(Date, VBA.vbDateTimeFormat.vbLongDate) = 24 October 2008
Debug.Print FormatDateTime(Date, VBA.vbDateTimeFormat.vbShortDate) = 24/10/2008
Debug.Print FormatDateTime(Date + Time(), VBA.vbDateTimeFormat.vbLongTime) = 17:31:15
Debug.Print FormatDateTime(Time(), VBA.vbDateTimeFormat.vbLongTime) = 17:31:15
Debug.Print FormatDateTime(Time(), VBA.vbDateTimeFormat.vbShortTime) = 17:32

Dim dtDate As Date
dtDate = #01/07/2011#
Debug.Print FormatDateTime(dtDate, vbGeneralDate)
Debug.Print FormatDateTime(dtDate, vbLongDate)
Debug.Print FormatDateTime(dtDate, vbShortDate)
Debug.Print FormatDateTime(dtDate, vbLongTime)
Debug.Print FormatDateTime(dtDate, vbShortTime)

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