VBA/Excel/Access/Word/Data Type Functions/Format
Содержание
Format$(Now, "DDD")
<source lang="vb">
Sub FormatData()
Debug.Print Format$(Now, "DDD")
End Sub
</source>
Format$(Now, "DDDD")
<source lang="vb">
Sub FormatData()
Debug.Print Format$(Now, "DDDD")
End Sub
</source>
Format$(Now, "Short Date")
<source lang="vb">
Sub FormatData()
Debug.Print Format$(Now, "Short Date")
End Sub
</source>
Format$(Now, "WW")
<source lang="vb">
Sub FormatData()
Debug.Print Format$(Now, "WW")
End Sub
</source>
Format$(Now, "YYYY")
<source lang="vb">
Sub FormatData()
Debug.Print Format$(Now, "YYYY")
End Sub
</source>
Format Phone number
<source lang="vb">
Sub formatPhone()
Debug.Print Format("1111111111", "(&&&)&&&-&&&&")
End Sub
</source>
Format Postal code
<source lang="vb">
Sub FormatPostalCode()
Debug.Print Format("qqqqqqqqq", "!&&&&&-&&&&")
End Sub
</source>
Illustrate the Format method
<source lang="vb">
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
</source>
The Format function formats expressions in the style specified
<source lang="vb">
Sub FormatData()
Debug.Print Format$(50, "Currency")
End Sub
</source>