Attached are doc's and other example, explaining how to work with Date and Time data.
Expand|Select|Wrap|Line Numbers
- Option Explicit
- Private Sub Form_Load()
- Dim MYDATE As Date
- Dim MYTIME As Date
- Dim MYDATETIME As Date
- Dim TEXTSTRING As String
- With Me
- .Caption = "Working with date and time_5. Formating"
- .AutoRedraw = True
- .Height = 13000
- .Width = 10000
- .Top = 0
- .Left = 0
- End With
- MYDATE = "9/6/2004" '§ weekday= thursday
- MYTIME = "2:6:9"
- MYDATETIME = "9/6/2004 2:6:9" '§ weekday= thursday
- Print "Format Function"
- '§ User-Defined Date/Time Formats
- Print "User-Defined Date/Time Formats"
- '§ DATE
- Print "== Date =="
- Print "Format(MYDATE, "; """"; "dd/mm/yy"; """"; ") !! Date separator !! ==>"; _
- Tab(80); Format(MYDATE, "dd/mm/yy")
- Print "Format(MYDATETIME, "; """"; "dd-mm-yy"; """"; ") !! other characters may be used !! ==>"; _
- Tab(80); Format(MYDATETIME, "dd-mm-yy")
- Print "Format(MYDATE, "; """"; "d"; """"; ") !! number without a leading zero !! ==>"; _
- Tab(80); Format(MYDATE, "d")
- Print "Format(MYDATE, "; """"; "dd"; """"; ") !! number with a leading zero !! ==>"; _
- Tab(80); Format(MYDATE, "dd")
- Print "Format(MYDATE, "; """"; "ddd"; """"; ") !! abbreviation !! ==>"; _
- Tab(80); Format(MYDATE, "ddd")
- Print "Format(MYDATE, "; """"; "dddd"; """"; ") !! full name !! ==>"; _
- Tab(80); Format(MYDATE, "dddd")
- Print "Format(MYDATE, "; """"; "ddddd"; """"; ") !! complete date !! ==>"; _
- Tab(80); Format(MYDATE, "ddddd")
- Print "Format(MYDATE, "; """"; "dddddd"; """"; ") !! serial number as a complete date !! ==>"; _
- Tab(80); Format(MYDATE, "dddddd")
- Print "Format(MYDATE, "; """"; "w"; """"; ") !! day of the week as a number (first day of week: Sunday) !! ==>"; _
- Tab(100); Format(MYDATE, "w")
- Print "Format(MYDATE, "; """"; "w"; """"; ", vbThursday) !! day of the week as a number (first day of week: Thursday) !! ==>"; _
- Tab(100); Format(MYDATE, "w", vbThursday)
- Print "Format(MYDATE, "; """"; "ww"; """"; ") !! week of the year as a number (first week: with 1 Jan) !! ==>"; _
- Tab(100); Format(MYDATE, "ww")
- Print "Format(MYDATE, "; """"; "ww"; """"; ", , vbFirstFullWeek) !! first week: first full week !! ==>"; _
- Tab(100); Format(MYDATE, "ww", , vbFirstFullWeek)
- Print "Format(MYDATE, "; """"; "m"; """"; ") !! month as a number without a leading zero !! ==>"; _
- Tab(80); Format(MYDATE, "m")
- Print "Format(MYDATE, "; """"; "mm"; """"; ") !! month as a number with a leading zero !! ==>"; _
- Tab(80); Format(MYDATE, "mm")
- Print "Format(MYDATE, "; """"; "mmm"; """"; ") !! month as an abbreviation !! ==>"; _
- Tab(80); Format(MYDATE, "mmm")
- Print "Format(MYDATE, "; """"; "mmmm"; """"; ") !! month as a full month name !! ==>"; _
- Tab(80); Format(MYDATE, "mmmm")
- Print "Format(MYDATE, "; """"; "q"; """"; ") !! quarter of the year as a number !! ==>"; _
- Tab(80); Format(MYDATE, "q")
- Print "Format(MYDATE, "; """"; "y"; """"; ") !! day of the year as a number !! ==>"; _
- Tab(80); Format(MYDATE, "y")
- Print "Format(MYDATE, "; """"; "yy"; """"; ") !! year as a 2-digit numbe !! ==>"; _
- Tab(80); Format(MYDATE, "yy")
- Print "Format(MYDATE, "; """"; "yyyy"; """"; ") !! year as a 4-digit number !! ==>"; _
- Tab(80); Format(MYDATE, "yyyy")
- '§ Time
- Print "== Time =="
- Print "Format(MYTIME, "; """"; "hh-nn-ss"; """"; ") !! Time separator !! ==>"; _
- Tab(80); Format(MYTIME, "hh-nn-ss")
- Print "Format(MYDATETIME, "; """"; "hh.nn.ss"; """"; ") !! Time separator !! ==>"; _
- Tab(80); Format(MYDATETIME, "hh.nn.ss")
- Print "Format(MYTIME, "; """"; "h"; """"; ") !! hour as a number without leading zeros !! ==>"; _
- Tab(80); Format(MYTIME, "h")
- Print "Format(MYTIME, "; """"; "hh"; """"; ") !! hour as a number with leading zeros !! ==>"; _
- Tab(80); Format(MYTIME, "hh")
- Print "Format(MYTIME, "; """"; "n"; """"; ") !! minute as a number without leading zeros !! ==>"; _
- Tab(80); Format(MYTIME, "n")
- Print "Format(MYTIME, "; """"; "nn"; """"; ") !! minute as a number with leading zeros !! ==>"; _
- Tab(80); Format(MYTIME, "nn")
- Print "Format(MYTIME, "; """"; "s"; """"; ") !! second as a number without leading zeros !! ==>"; _
- Tab(80); Format(MYTIME, "s")
- Print "Format(MYTIME, "; """"; "ss"; """"; ") !! second as a number with leading zeros !! ==>"; _
- Tab(80); Format(MYTIME, "ss")
- Print "Format(MYTIME, "; """"; "ttttt"; """"; ") !! complete time !! ==>"; _
- Tab(80); Format(MYTIME, "ttttt")
- Print "Format(MYTIME, "; """"; "h.n.s AM/PM"; """"; ") !! 12-hour clock and 'AM' before noon; 'PM' between noon and 11:59 P.M !! ==>"; _
- Tab(110); Format(MYTIME, "h.n.s AM/PM")
- Print "Format(MYTIME, "; """"; "h.n.s am/pm"; """"; ") !! 12-hour clock and 'am' before noon; 'pm' between noon and 11:59 P.M !! ==>"; _
- Tab(110); Format(MYTIME, "h.n.s am/pm")
- Print "Format(MYTIME, "; """"; "h.n.s A/P"; """"; ") !! 12-hour clock and 'A' before noon; 'P' between noon and 11:59 P.M !! ==>"; _
- Tab(110); Format(MYTIME, "h.n.s A/P")
- Print "Format(MYTIME, "; """"; "h.n.s a/p"; """"; ") !! 12-hour clock and 'a' before noon; 'p' between noon and 11:59 P.M !! ==>"; _
- Tab(110); Format(MYTIME, "h.n.s a/p")
- Print "Format(MYTIME, "; """"; "h.n.s AMPM"; """"; ") !! 12-hour clock, AM and PM string literal as defined by your system !! ==>"; _
- Tab(110); Format(MYTIME, "h.n.s AMPM")
- '§ Date and Time
- Print "== Date and Time =="
- Print "Format(MYDATETIME, "; """"; "c"; """"; ") !! date as ddddd and the time as ttttt !! ==>"; _
- Tab(80); Format(MYDATETIME, "c")
- Print "Format(MYDATETIME, "; """"; "dd-mm-yy h.n.s AM/PM"; """"; ") !! mix !! ==>"; _
- Tab(80); Format(MYDATETIME, "dd-mm-yy h.n.s AM/PM")
- Print "============================================"
- '§ Predefined date and time format names
- Print "Predefined date and time format names"
- '§ DATE
- Print "== Date =="
- Print "Format(MYDATETIME, "; """"; "General Date"; """"; ") !! is determined by your system settings !! ==>"; _
- Tab(110); Format(MYDATETIME, "General Date")
- Print "Format(MYDATETIME, "; """"; "Long Date"; """"; ") !! according to your system's long date format !! ==>"; _
- Tab(110); Format(MYDATETIME, "Long Date")
- Print "Format(MYDATETIME, "; """"; "Medium Date"; """"; ") !! appropriate for the language version of the host application !! ==>"; _
- Tab(110); Format(MYDATETIME, "Medium Date")
- Print "Format(MYDATETIME, "; """"; "Short Date"; """"; ") !! using system's short date format !! ==>"; _
- Tab(110); Format(MYDATETIME, "Short Date")
- '§ Time
- Print "== Time =="
- Print "Format(MYDATETIME, "; """"; "Long Time"; """"; ") !! system's long time format !! ==>"; _
- Tab(110); Format(MYDATETIME, "Long Time")
- Print "Format(MYDATETIME, "; """"; "Medium Time"; """"; ") !! in 12-hour format using hours and minutes and the system AM/PM !! ==>"; _
- Tab(110); Format(MYDATETIME, "Medium Time")
- Print "Format(MYDATETIME, "; """"; "Short Time"; """"; ") !! 24-hour format !! ==>"; _
- Tab(110); Format(MYDATETIME, "Short Time")
- Print "##########################################################"
- Print "FormatDateTime Function"
- '§ User-Defined Date/Time Formats
- Print "User-Defined Date/Time Formats"
- '§ DATE
- Print "== Date =="
- Print "FormatDateTime(MYDATETIME, vbGeneralDate) !! is determined by your system settings !! ==>"; _
- Tab(110); FormatDateTime(MYDATETIME, vbGeneralDate)
- Print "FormatDateTime(MYDATETIME, vbLongDate) !! according to your system's long date format !! ==>"; _
- Tab(110); FormatDateTime(MYDATETIME, vbLongDate)
- Print "FormatDateTime(MYDATETIME, vbShortDate) !! using system's short date format !! ==>"; _
- Tab(110); FormatDateTime(MYDATETIME, vbShortDate)
- '§ Time
- Print "== Time =="
- Print "FormatDateTime(MYDATETIME, vbLongTime) !! system's long time format !! ==>"; _
- Tab(110); FormatDateTime(MYDATETIME, vbLongTime)
- Print "FormatDateTime(MYDATETIME, vbShortTime) !! 24-hour format !! ==>"; _
- Tab(110); FormatDateTime(MYDATETIME, vbShortTime)
- End Sub