Name
DatePart Function
Class
Microsoft.VisualBasic.DateAndTime
Syntax
DatePart(interval, datevalue[,firstdayofweekvalue[, _firstweekofyearvalue]])
-
interval Use: Required
Data Type: String or a member of the
DateIntervalenumA String literal (see the second item in Section ) or a constant of the
DateIntervalenum (see the third item in Section ) that defines the part of the date/time to extract fromdatevalue-
datevalue Use: Required
Data Type: Date, literal date, or an expression capable of conversion to a date
The Date value to evaluate
-
firstdayofweekvalue Use: Optional
Data Type:
FirstDayOfWeekenumA member of the
FirstDayOfWeekenum-
firstweekofyearvalue Use: Optional
Data Type:
FirstWeekOfYearenumA member of the
FirstWeekOfYearenum
Return Value
An Integer containing the specified part
Description
Extracts an individual component of the date or time (like the month or the second) from a date/time value
Rules at a Glance
The
DatePartfunction returns an Integer containing the specified portion of the given date.DatePartis a single function encapsulating the individualYear,Month,Day,Hour,Minute, andSecondfunctions.intervalcan be one of the following literal strings:
|
String |
Description |
|---|---|
|
|
Year |
|
|
Quarter |
|
|
Month |
|
|
Day of year |
|
|
Day |
|
|
Weekday |
|
|
Week |
|
|
Hour |
|
|
Minute |
|
|
Second |
intervalcan also be a member of theDateIntervalenum:Enum DateInterval Day DayOfYear Hour Minute Month Quarter Second Week Weekday WeekOfYear End Enum
The
firstdayofweekvalue ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access