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
* This function was added in Office 2000.
* 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"), VbDateTimeFormat.vbGeneralDate) = 24/10/2008 04:30:00 
Debug.Print FormatDateTime(Date + Time(), VbDateTimeFormat.vbLongDate) = 24 October 2008
Debug.Print FormatDateTime(Date, VbDateTimeFormat.vbLongDate) = 24 October 2008
Debug.Print FormatDateTime(Date, VbDateTimeFormat.vbShortDate) = 24/10/2008
Debug.Print FormatDateTime(Date + Time(), VbDateTimeFormat.vbLongTime) = 17:31:15
Debug.Print FormatDateTime(Time(), VbDateTimeFormat.vbLongTime) = 17:31:15
Debug.Print FormatDateTime(Time(), 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)

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