VBScript: More Fun with the Date Functions
(Page 1 of 6 )
In our first article on VBScript date functions, way back in January, we covered CDate, Date, DateAdd, and DateDiff. In this article, we'll be picking up where we left off. We still have a lot of ground to cover; who knew dates were so important? So let's get started.
If you happened to miss the wise words of my first VBScript article on dates, never fear, you can review it right here. If you'd rather not, that's okay too.
We left off discussing the difference between my birth and Jesus's hypothetical hundredth birthday using the DateDiff function. Here we will carry on beginning with a little number I like to call the DatePart...
But first, our lovely table:
Function Name | What It Does |
CDate | Used to change the date and time expression to the variant subtype Date |
Date | Used to return the current date, based on your system date |
DateAdd | Used to return a date in which a time interval you specified has been added |
DateDiff | Used to return the difference between two dates |
DatePart | Used to return a specific part of a date |
DateSerial | Used to return the date for a year you specify: year, month, and day |
DateValue | Used to return a date |
Day | Used to return a day of the month; Returns a number between 1 and 31 |
FormatDateTime | Used to return an expression. Formats it as a date or as a time |
Hour | Used to return the hour. Returns a number between 0 and 23. |
IsDate | Used to check if a value can be converted to a date. Returns a boolean value. |
Minute | Used to return the minutes of an hour. Value range is between 0 and 59. |
Month | Returns the month. Value returned is a number ranging from 1-12. |
MonthName | Returns the name of a month you specifiy. |
Now | Returns the date and time based on your system's date and time. |
Second | Returns the seconds of the minute. A value between 0 and 59. |
Time | Used to return the system time. |
Timer | Used to return the amount of seconds since 12:00 am. |
TimeSerial | Used to return the time for a specified hour, minute, and second. |
TimeValue | Used to return a time |
Weekday | Used to return a day of the week. Value is a number between 1 and 7 |
WeekDayName | Used to return the name of a day in the week |
Year | Used to return a year. Value is a number representing the year. (Duh) |
Partying with the DatePart Function
DatePart allows you to extract a part of a date. Note that like most date functions, you can use the following parameters:
Here are some samples:
Next: Parsing out the Month, Day, and Year from the Current Date: >>
More BrainDump Articles
More By James Payne