Date formatting in VBScript
Examples
'*******************************************************************************
http://www.mikesdotnetting.com/Article/22/Date-formatting-in-VBScript
Date() 08/04/2007
Now() 08/04/2007 20:20:15
Time() 20:20:15
FormatDateTime(Now(),vbGeneralDate) 08/04/2007 20:20:15
FormatDateTime(Now(),vbLongDate) 08 April 2007
FormatDateTime(Now(),vbShortDate) 08/04/2007
FormatDateTime(Now(),vbLongTime) 20:20:15
FormatDateTime(Now(),vbShortTime) 20:20
Year(Now()) 2007
Month(Now()) 4
Day(Now()) 8
Hour(Now()) 20
Minute(Now()) 20
Second(Now()) 15
WeekDay(Now()) 1
WeekDayName(WeekDay(Now())) Sunday
WeekDayName(WeekDay(Now()),1) Sun
MonthName(Month(Now())) April
MonthName(Month(Now()),1) Apr
DatePart("d", Now) 8 (Day of Month)
DatePart("w", Now) 1 (Week of Month)
DatePart("m", Now) 4 (Month of Year)
DatePart("ww", Now) 15 (Week of Year)
DatePart("y", Now) 98 (Day of Year)
DatePart("yyyy", Now) 2007 (Year)
DatePart("q", Now) 2 (Quarter)
DatePart("h", Now) 20 (Hour)
DatePart("n", Now) 20 (Minute)
DatePart("s", Now) 15 (Second)
DatePart("ww", Now, vbUseSystem) 14
DatePart("ww", Now, vbFirstJan1) 15
DatePart("ww", Now, vbFirstFourDays) 14
DatePart("ww", Now, VbFirstFullWeek) 15
'*******************************************************************************
Examples
'*******************************************************************************
'Function to get the previous date in the format "01-JAN-2011"
Function
Get_Previous_Date(Date_Difference)
Dt = Date-Date_Difference
D = DatePart("d", Dt, VbFirstFullWeek)
M = MonthName(Month(Dt),1)
Y = Year(Dt)
If D<10 Then
D = "0"&D
Else
End If
Get_Previous_Date = Trim(D & "-" & M & "-" & Y)
End Function
'******************************************************************************* Dt = Date-Date_Difference
D = DatePart("d", Dt, VbFirstFullWeek)
M = MonthName(Month(Dt),1)
Y = Year(Dt)
If D<10 Then
D = "0"&D
Else
End If
Get_Previous_Date = Trim(D & "-" & M & "-" & Y)
End Function
http://www.mikesdotnetting.com/Article/22/Date-formatting-in-VBScript
Date() 08/04/2007
Now() 08/04/2007 20:20:15
Time() 20:20:15
FormatDateTime(Now(),vbGeneralDate) 08/04/2007 20:20:15
FormatDateTime(Now(),vbLongDate) 08 April 2007
FormatDateTime(Now(),vbShortDate) 08/04/2007
FormatDateTime(Now(),vbLongTime) 20:20:15
FormatDateTime(Now(),vbShortTime) 20:20
Year(Now()) 2007
Month(Now()) 4
Day(Now()) 8
Hour(Now()) 20
Minute(Now()) 20
Second(Now()) 15
WeekDay(Now()) 1
WeekDayName(WeekDay(Now())) Sunday
WeekDayName(WeekDay(Now()),1) Sun
MonthName(Month(Now())) April
MonthName(Month(Now()),1) Apr
DatePart("d", Now) 8 (Day of Month)
DatePart("w", Now) 1 (Week of Month)
DatePart("m", Now) 4 (Month of Year)
DatePart("ww", Now) 15 (Week of Year)
DatePart("y", Now) 98 (Day of Year)
DatePart("yyyy", Now) 2007 (Year)
DatePart("q", Now) 2 (Quarter)
DatePart("h", Now) 20 (Hour)
DatePart("n", Now) 20 (Minute)
DatePart("s", Now) 15 (Second)
DatePart("ww", Now, vbUseSystem) 14
DatePart("ww", Now, vbFirstJan1) 15
DatePart("ww", Now, vbFirstFourDays) 14
DatePart("ww", Now, VbFirstFullWeek) 15
'*******************************************************************************
No comments:
Post a Comment