O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

DatePart Function

Class

Microsoft.VisualBasic.DateAndTime

Syntax

DatePart(interval, datevalue[,firstdayofweekvalue[, _
        firstweekofyearvalue]])
interval (required; String or a member of the DateInterval enum)

A String literal (see the second item in Section ) or a constant of the DateInterval enum (see the third item in Section ) that defines the part of the date/time to extract from datevalue

datevalue (required; Date, literal date, or an expression capable of conversion to a date)

The Date value to evaluate

firstdayofweekvalue (optional; FirstDayOfWeek enum)

A member of the FirstDayOfWeek enum

firstweekofyearvalue (optional; FirstWeekOfYear enum)

A member of the FirstWeekOfYear enum

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 DatePart function returns an Integer containing the specified portion of the given date. DatePart is a single function encapsulating the individual Year, Month, Day, Hour, Minute, and Second functions.

  • interval can be one of the following literal strings:

String

Description

yyyy

Year

q

Quarter

m

Month

y

Day of year

d

Day

w

Weekday

ww

Week

h

Hour

n

Minute

s

Second

  • interval can also be a member of the DateInterval enum:

    Enum DateInterval
       Day
       DayOfYear
       Hour
       Minute
       Month
       Quarter
       Second
       Week
       Weekday
       WeekOfYear
    End Enum
  • The firstdayofweekvalue argument can be any of the following members of the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required