DatePart

Return a unit of time from a date.

Syntax 
      DatePart (interval,date [, FirstDayofWeek [, FirstWeekofYear]])

Key
    date      The date to anaylyse

FirstDayofWeek A constant defining the first day of the week:
               vbUseSystem (0), vbSunday (1=default),vbMonday(2), 
               vbTuesday(3), vbWednesday(4), vbThursday(5),
               vbFriday(6), vbSaturday(7)

FirstWeekofYear A constant defining the first week of the year:
               vbUseSystem(0), vbFirstJan1(1),vbFirstFourDays(2),
               vbFirstFullWeek(3) 

    interval   The date/Time interval to express in the result:

                 yyyy  Year
                  q    Quarter
                  m    Month
                  y    Day of year
                  d    Day
                  w    Weekday
                  h    Hour
                  n    Minute
                  s    Second

Example

dtm1="18-Feb-10"
WScript.Echo dtm1
intMonthsinDate=DatePart("m", dtm1)
WScript.Echo intMonthsinDate

“Christmas, children, is not a date. It is a state of mind” - Mary Ellen Chase

Related:

Date - The current system date
DateAdd - Add a time interval to a Date
DateDiff - Return the time interval between two dates
DateSerial - Return a Date from a numeric Year, Month and Day
Equivalent Powershell command: Get-Date



Back to the Top

© Copyright SS64.com 1999-2012
Some rights reserved