Customer Login  .   Webmail Login  .   About Us  .   Contact Us
Go to: Articles List

Date Manipulation Part 1 : Extracting parts of the date out with DatePart()

DatePart(PartOfDate, Date[, FirstDayOfWeek, FirstDayOfYear])
- returns the request part of the date
- optional parameters are setting the first day of the week (defaults to Sunday), and setting the first week of the year (defaults to Jan 1).

FirstDayOfWeek optional parameter can have one of the following values:
0 - Use National Language Support API setting
1 - Sunday (the default value if this parameter is not supplied)
2 - Monday
3 - Tuesday
4 - Wednesday
5 - Thursday
6 - Friday
7 - Saturday

FirstDayOfYear optional parameter can have one of the following values:
0 - Use National Language Support API setting
1 - Start with the week that has Jan 1 in it (the default value if this parameter is not supplied)
2 - Start with the first week that contains at least four days in the new year.
3 - Start with the first week that is a full week in the new year.

- I recommend just leaving the two optional parameters out unless they specifically apply to what you are currently trying to do.

PartOfDate parameter can have the following values:
yyyy - Year
q - Quarter
m - Month
y - Day of year
d - Day
w - Weekday
ww - Week of year
h - Hour
n - Minute
s - Second

An example of what each of those values will output is:

var1 = Now()
Response.Write("var1 = " & var1 & "<br>")
Response.Write("var1 part yyyy = " & DatePart("yyyy", var1) & "<br>")
Response.Write("var1 part m = " & DatePart("m", var1) & "<br>")
Response.Write("var1 part q = " & DatePart("q", var1) & "<br>")
Response.Write("var1 part y = " & DatePart("y", var1) & "<br>")
Response.Write("var1 part d = " & DatePart("d", var1) & "<br>")
Response.Write("var1 part w = " & DatePart("w", var1) & "<br>")
Response.Write("var1 part ww = " & DatePart("ww", var1) & "<br>")
Response.Write("var1 part h = " & DatePart("h", var1) & "<br>")
Response.Write("var1 part n = " & DatePart("n", var1) & "<br>")
Response.Write("var1 part s = " & DatePart("s", var1) & "<br>")

Results:
var1 = 9/1/99 1:18:15 PM
var1 part yyyy = 1999
var1 part m = 9
var1 part q = 3
var1 part y = 244
var1 part d = 1
var1 part w = 4
var1 part ww = 36
var1 part h = 13
var1 part n = 18
var1 part s = 15

Shared Hosting
Rookie
Pro
Advanced
Dedicated Servers
BASE
BUSINESS
ENTERPRISE
Why Choose Brinkster?
Radical Support
Brinkster Datacenter
Brinkster Network
Corporate Social Responsibility
90 Day Money Back Guarantee
Unsurpassed Value
Client Testimonials
Additional Features
Antivirus
Merchant Account
E-Commerce
Live Chat Communicator
Free Firewall
Website Builder
Free Web Hosting
Support
General Support
Codebank Search
Forums
Articles
Click here for Brinkster Live Chat
Home   Domains   Shared Hosting   Dedicated Hosting   Partner   Support   About Us    Contact Us   Webmail
Copyright © Brinkster Communications Corporation All Rights Reserved. Privacy Policy & Legal