Quick References
      ADO
      ASP
      CSS2
      HTML
      JavaScript
      Jet SQL
      VBScript
      WML
      WMLScript
      WSH
      XHTML
      XML DOM
      XSLT

Features
      Knowledge Base
      Tutorials

Partners
     ZVON.ORG
     XML
     Planet Source Code
     VisualBuilder
     Web Design
     Your HTML Source
     XML/XSLT Forums
     ASPAlliance
     Scripts
     
     Programmers Heaven
     Tek-Tips Forums
     Developer Fusion
     Code Project











FUNCTION:  DatePart( )

Implemented in version 2.0
 
DatePart(Interval, Date, FirstDayofWeek, FirstWeekofYear)
 
The DatePart function returns the designated part of the date.
 
There are two mandatory arguments.
 
Interval
 
The Interval argument designates the the type of time interval.
 
Only the following settings may be used. You must place the setting inside a pair of double quotes.
 
SETTING DESCRIPTION
YYYY Year
Q Quarter
M Month
Y Day Of Year
D Day
W WeekDay
WW Week Of Year
H Hour
N Minute
S Second

 
Date
 
The Date argument is the date and time you designate.
 
Code:
<% =Date %>
<% =DatePart("D", Date) %>

 
Output:
3/16/99
16

 
The weekday is given as a number from the Date And Time CONSTANTS which are listed below. In the example, 7 equals Saturday.
 
Code:
<% =DatePart("W", 1/1/2000) %>
 
Output:
7
 
There are two optional arguments.
 
FirstDayofWeek
 
The FirstDayofWeek argument must only use the constants or values defined below in the Date And Time CONSTANTS.
 
CONSTANT VALUE DESCRIPTION
VBSunday 1 Sunday
VBMonday 2 Monday
VBTuesday 3 Tuesday
VBWednesday 4 Wednesday
VBThursday 5 Thursday
VBFriday 6 Friday
VBSaturday 7 Saturday
VBFirstJan1 1 Week of January 1
VBFirstFourDays 2 First week of the year thathas at least four days
VBFirstFullWeek 3 First full week of the year
VBUseSystem 0 Use the date format of the computer's regionsl settings
VBUseSystemDayOfWeek 0 Use the first full day of the week as defined by the system settings

 
In this example, Tuesday is defined to be the first day of the week. Therefore, Saturday becomes the 5th day of the week.
 
Code:
<% =DatePart("W", "1/1/2000", 3) %>
 
Output:
5
 
Code:
<% =DatePart("W", "1/1/2000", VBTUESDAY) %>
 
Output:
5
 
FirstWeekofYear
 
The FirstWeekofYear argument must only use the constants or values defined in the Date And Time CONSTANTS which are listed above.
 
This example returns how many full 7 day weeks there were in 1999.
 
Code:
<% =DatePart("WW", "12/31/1999", 1, VBFIRSTFULLWeek) %>
 
Output:
52


 


Copyright 1999-2005 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information