Changes

Working with Dates and Times in Visual Basic

39 bytes added, 19:07, 2 August 2007
Formatting Dates and Times
The month can be formatted using sequences of 'M' characters. For example:
<pre>
Format(#8/2/2007#, "MM") - returns Month as 2 digits (i.e. 08)
Format(#8/2/2007#, "MMM") - returns abbreviated Month name (i.e. Aug)
Format(#8/2/2007#, "MMMM") - returns full Month name (i.e. August)
</pre>
Similarly the day of the month may be formatted using the 'd' character:
<pre>
Format(#8/2/2007#, "d") - returns day of month as 1 (day < 10) or 2 digits (day > 9) (i.e. 2 or 12)
Format(#8/2/2007#, "dd") - returns day of month as 2 digits (i.e. 02 or 12)
Format(#8/2/2007#, "ddd") - returns abbreviated day of week (i.e Tue)
Format(#8/2/2007#, "dddd") - returns unabbreviated day of week (i.e Tuesday)
</pre>
The 'y' character is used to control the formatting of the year:
<pre>
Format(#8/2/2007#, "y") - returns year as 1 digit (i.e. 7)
Format(#8/2/2007#, "yy") - returns year as 2 digits (i.e. 07)
Format(#8/2/2007#, "yyyy") - returns year as 4 digits (i.e. 2007)
</pre>
The format of the time may be formatted using 'h', 'm', 's' and 'tt' characters:
Format(#8/2/2007 1:02:00 PM#, hh:mm:ss tt) - returns as 01:02:00 PM