VBS equivalents of some Linux date command format sequences
Posted 02-27-2012 at 10:13 PM by catkin
Here are some Visual Basic Script statements that generate the effect of the Linux date command used with format sequences %y, %Y, %b, %B, %n, %a, %A, %d, %H, %I, %p, %M and %S
Code:
Const DATE_PART_ABBREVIATE = True Dim strValue ' %y for year, two digit strValue = Right(DatePart( "yyyy", Now), 2) ' %Y for year, four digit strValue = DatePart( "yyyy", Now)) ' %b for month name, example Jan strValue = MonthName(DatePart("m", Now), DATE_PART_ABBREVIATE) ' %B for month name, example January strValue = MonthName(DatePart("m", Now) ' %n for month number (01 to 12) strValue = Right( "0" & DatePart("m", Now), 2)) ' %a for day name, example Mon strValue = WeekdayName(DatePart("w", Now), DATE_PART_ABBREVIATE) ' %A for day name, example Monday strValue = WeekdayName(DatePart("w", Now)) ' %d for day of month, example 01 strValue = Right( "0" & Day(Now), 2) ' %H for hour (00 … 23) strValue = Right( "0" & DatePart("h", Now)) ' %I for hour (01 to 12) strValue = Right( "0" & DatePart("h", Now) Mod 12, 2) ' %p for AM or PM. According to ISO, 12:00 is ambiguous so arbirarily make it PM. If DatePart("h", Now) < 12 Then strValue = "AM" Else strValue = "PM" End If ' %M for minute (00 to 59) strValue = Right( "0" & DatePart("n", Now), 2)) ' %Sfor second (00 to 60) strValue = Right( "0" & DatePart("s", Now), 2))
Total Comments 0