Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

VBA-Excel: Date-Time Functions – FormatDateTime()

Description:

The For­mat­Date­Time func­tion takes date as a para­me­ter and returns the spec­i­fied for­mat­ted date or time.

Format:

FormatDateTime(strDate[,strFormat])

 Arguments:
    • str­Date
      • Manda­tory
      • Type: Date
      • Date which needs to be formatted.

  • str­For­mat
    • Optional
    • Type: Numeric
    • Numeric value which rep­re­sents the for­mat in which the date to be con­verted, if not pro­vided any value, vbGen­er­al­Date, 0 will be taken as default.
Con­stant Value Descrip­tion
vbGen­er­al­Date

0

Default, Returns Date: mm/dd/yyyy and if time spec­i­fied: hh:mm:ss PM/AM
vbLong­Date

1

Returns Date: weekDay,month Name, Year
vbShort­Date

2

Returns Date: mm/dd/yyyy
vbLong­Time

3

Returns Time: hh:mm:ss PM/AM
vbShort­Time

4

Returns Time: hh:mm

Exam­ple :

Function FnFormateDateTime()

   Dim strDate

   Dim strResult

   strDate = Now

   strResult = "General Format Date is: " & FormatDateTime(strDate) & vbCrLf

   strResult = strResult & "Long Format Date is: " & FormatDateTime(strDate, vbLongDate) & vbCrLf

   strResult = strResult & "Short Format Date is: " & FormatDateTime(strDate, vbShortDate) & vbCrLf

   strResult = strResult & "Long Format Time is: " & FormatDateTime(strDate, vbLongTime) & vbCrLf

   strResult = strResult & "Short Format Time is: " & FormatDateTime(strDate, vbShortTime) & vbCrLf

   MsgBox strResult

End Function
FormatDateTime()

For­mat­Date­Time()

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: