Formatting a date field
Private Sub FormatMyDate()
txtMyDate.text = FormatDateTime(CDate(txtMyDate.Text), DateFormat.ShortDate)
m_str_Cust_ID = Format(Now(), "MM/dd/yy") & " - " & Format(Now(), "hh:mmtt") & " - " & Format(int_Number_of_Clients + 1, "00")
End Sub
CURRENT MONTH
Me.cbo_Month.Text = Format(Now(), "MMMM")
Me.cbo_Month.SelectedValue = CType(IIf(CType(Month(Now()), Integer) = 1, 12, Month(Now()) - 1), String)
Me.cbo_Year.Text = CType(IIf(CType(Month(Now()), Integer) = 1, Year(Now()) - 1, Year(Now())), String)
PREVIOUS MONTH
Me.cbo_Month.Text = Format(CType(Month(Now()) - 1 & "/" & Microsoft.VisualBasic.DateAndTime.Day(Now()) & "/" & Year(Now()), Date), "MMMM")
or
Me.cbo_Year.Text = CType(IIf(CType(Month(Now()), Integer) = 1, Year(Now()) - 1, Year(Now())), String)
Dim MyDateTime As Date = #1/27/2001 5:04:23 PM#
Dim MyStr As String
' Returns current system time in the system-defined long time format.
MyStr = Format(Now(), "Long Time")
' Returns current system date in the system-defined long date format.
MyStr = Format(Now(), "Long Date")
' Also returns current system date in the system-defined long date
' format, using the single letter code for the format.
MyStr = Format(Now(), "D")
' Returns the value of MyDateTime in user-defined date/time formats.
MyStr = Format(MyDateTime, "h:m:s") ' Returns "5:4:23".
MyStr = Format(MyDateTime, "hh:mm:ss tt") ' Returns "05:04:23 PM".
MyStr = Format(MyDateTime, "dddd, MMM d yyyy") ' Returns "Saturday,
' Jan 27 2001".
MyStr = Format(MyDateTime, "HH:mm:ss") ' Returns "17:04:23"
MyStr = Format(23) ' Returns "23".
' User-defined numeric formats.
MyStr = Format(5459.4, "##,##0.00") ' Returns "5,459.40".
MyStr = Format(334.9, "###0.00") ' Returns "334.90".
MyStr = Format(5, "0.00%") ' Returns "500.00%".