DatePart Function


DatePart Function

Class

Microsoft.VisualBasic.DateAndTime

Syntax

     DatePart(interval, dateValue[, firstDayOfWeekValue[, _         firstWeekOfYearValue]]) 


interval (required; String or DateInterval enumeration)

A String expression or Microsoft.VisualBasic.DateInterval enumeration item indicating which part of the date to return. The following table lists both the string and enumeration choices.

String

DateInterval

Description

d

Day

The day of the month, from 1 to 31

y

DayOfYear

The day of the year, from 1 to 366

h

Hour

The hour of the day, from 0 to 23

n

Minute

The minute of the hour, from 0 to 59

m

Month

The month of the year, from 1 to 12

q

Quarter

The quarter of the year, from 1 to 4

s

Second

The second of the minute, from 0 to 59

w

Weekday

The day of the week, from 1 to 7; the value 1 is normally used for Sunday, but it may differ based on the firstDayOfWeekValue parameter

ww

WeekOfYear

The week number of the year, from 1 to 53; the firstWeekOfYearValue parameter impacts this value

yyyy

Year

The year of the Gregorian calendar, from 1 AD to 9999 AD



dateValue (required; Date or date expression)

The date from which to extract a component.


firstDayOfWeekValue (optional; FirstDayOfWeek enumeration)

Indicates the first day of the week. One of the following Microsoft.VisualBasic.FirstDayOfWeek enumeration members: Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, or System (to use the regional default). If omitted, Sunday is used.


firstWeekOfYearValue (optional; FirstWeekOfYear enumeration)

Indicates which week counts as the first week of a given year. One of the following Microsoft.VisualBasic.FirstWeekOfYear enumeration members.

Value

Description

System

Uses the system-defined value

Jan1

Uses the week in which January 1 appears

FirstFourDays

Uses the first week of the year that has at least four days in it

FirstFullWeek

Uses the first week of the year that has a full seven days in it


If omitted, Jan1 is used.

Description

The DatePart function returns an individual component of the date or time (such as the month or the second) from a date or time value.

Usage at a Glance

  • DatePart replicates the functionality of the distinct Year, Month, Day, Hour, Minute, and Second functions.

  • You can check that a date expression is valid using the IsDate function.

Version Differences

  • VB 6 lacks the DateInterval enumeration and therefore only accepts a string as the interval argument.

  • VB 6 supports a number of constants beginning with vb... (such as vbSunday) as values for the firstDayOfWeekValue and firstWeekOfYearValue arguments. While these are still supported in .NET, the new FirstDayOfWeek and FirstWeekOfYear enumerations are preferred.

See Also

DateSerial Function, DateString Property, DateValue Function




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net