Illustrate the Format method : Format « Data Type Functions « VBA / Excel / Access / Word






Illustrate the Format method

 
Sub dateFormats()
   Dim strDateString As String
   
   strDateString = "m/d/yy: " & Format(Now, "m/d/yy") & vbCrLf & _
                   "d-mmm-yy: " & Format(Now, "d-mmm-yy") & vbCrLf & _
                   "d-mmmm-yy: " & Format(Now, "d-mmmm-yy") & vbCrLf & _
                   "mmmm d, yyyy: " & Format(Now, "mmmm d, yyyy") & vbCrLf & _
                   "ddd: " & Format(Now, "ddd") & vbCrLf & _
                   "dddd: " & Format(Now, "dddd") & vbCrLf & _
                   "ddddd: " & Format(Now, "ddddd") & vbCrLf & _
                   "dddddd: " & Format(Now, "dddddd") & vbCrLf & _
                   "Hh:Nn:Ss AM/PM: " & Format(Now, "Hh:Nn:Ss AM/PM") & vbCrLf & _
                   "ttttt: " & Format(Now, "ttttt") & vbCrLf & _
                   "vbShortDate: " & FormatDateTime(Now, vbShortDate) & vbCrLf & _
                   "vbLongDate: " & FormatDateTime(Now, vbLongDate) & vbCrLf & _
                   "vbGeneralDate: " & FormatDateTime(Now, vbGeneralDate)
   
   MsgBox strDateString
End Sub

 








Related examples in the same category

1.The Format function formats expressions in the style specified
2.Format$(Now, "Short Date")
3.Format$(Now, "DDDD")
4.Format$(Now, "DDD")
5.Format$(Now, "YYYY")
6.Format$(Now, "WW")
7.Format Phone number
8.Format Postal code