LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > catkin
User Name
Password

Notices


Rate this Entry

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))
Posted in Uncategorized
Views 1771 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 09:58 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration