Flash Tip: September 19, 2007
Flash Tip: Illustrated Script - Using the DatePart Function
Q: How do I use the DatePart Function?
A: The following script parses the current date and time, and then displays each date time component.
Wscript.Echo Now
Wscript.Echo "Year: " & DatePart("yyyy" , Now)
Wscript.Echo "Quarter: " & DatePart("q", Now)
Wscript.Echo "Month: " & DatePart("m" , Now)
Wscript.Echo "Day of Year: " & DatePart("y" , Now) Wscript.Echo "Day: " & DatePart("d" , Now)
Wscript.Echo "Weekday: " & DatePart("w" , Now)
Wscript.Echo "Week of Year: " & DatePart("ww" , Now)
Wscript.Echo "Hour: " & DatePart("h", Now)
Wscript.Echo "Minute: " & DatePart("n" , Now)
Wscript.Echo "Seconds: " & DatePart("s" , Now)
When the preceding script was run on January 17, 2002, at 11:40:27 AM, the following output was returned:
1/17/2002 11:40:27 AM
Year: 2002
Quarter: 1
Month: 1
Day of Year: 17
Day: 17
Weekday: 5
Week of Year: 3
Hour: 11
Minute: 40
Seconds: 27
Based on "VBScript Primer," from the book Microsoft Windows 2000 Scripting Guide by Microsoft Corporation. Reprinted by permission of Microsoft Press. All rights reserved. For more information, go to http://www.microsoft.com/MSPress/books/6417.aspx.