VBScript DatePart Function

It is a function that returns the specific part of a given date.
DatePart(interval,date[,firstdayofweek[,firstweekofyear]]) 

Interval, a Required Parameter. It can take the following values −

d − day of the year.
m − month of the year
y − year of the year
yyyy − year
w − weekday
ww − week
q − quarter
h − hour
m − n
s − second


Interval, a Required Parameter. It can take the following values −
d − day of the year.
d − day of the year.
m − month of the year
m − month of the year
y − year of the year
y − year of the year
yyyy − year
yyyy − year
w − weekday
w − weekday
ww − week
ww − week
q − quarter
q − quarter
h − hour
h − hour
m − n
m − n
s − second
s − second
date1 is a required parameter.
date1 is a required parameter.
firstdayofweek is Optional. Specifies the first day of the week. It can take the following values −

0 = vbUseSystemDayOfWeek − Use National Language Support (NLS) API setting
1 = vbSunday − Sunday 
2 = vbMonday − Monday
3 = vbTuesday − Tuesday
4 = vbWednesday − Wednesday
5 = vbThursday − Thursday
6 = vbFriday − Friday
7 = vbSaturday − Saturday


firstdayofweek is Optional. Specifies the first day of the week. It can take the following values −
0 = vbUseSystemDayOfWeek − Use National Language Support (NLS) API setting
0 = vbUseSystemDayOfWeek − Use National Language Support (NLS) API setting
1 = vbSunday − Sunday 
1 = vbSunday − Sunday 
2 = vbMonday − Monday
2 = vbMonday − Monday
3 = vbTuesday − Tuesday
3 = vbTuesday − Tuesday
4 = vbWednesday − Wednesday
4 = vbWednesday − Wednesday
5 = vbThursday − Thursday
5 = vbThursday − Thursday
6 = vbFriday − Friday
6 = vbFriday − Friday
7 = vbSaturday − Saturday
7 = vbSaturday − Saturday
firstdayofyear is Optional. Specifies the first day of the year. It can take the following values −

0 = vbUseSystem − Use National Language Support (NLS) API setting
1 = vbFirstJan1 − Start with the week in which January 1 occurs (default)
2 = vbFirstFourDays − Start with the week that has at least four days in the new year
3 = vbFirstFullWeek − Start with the first full week of the new year


firstdayofyear is Optional. Specifies the first day of the year. It can take the following values −
0 = vbUseSystem − Use National Language Support (NLS) API setting
0 = vbUseSystem − Use National Language Support (NLS) API setting
1 = vbFirstJan1 − Start with the week in which January 1 occurs (default)
1 = vbFirstJan1 − Start with the week in which January 1 occurs (default)
2 = vbFirstFourDays − Start with the week that has at least four days in the new year
2 = vbFirstFourDays − Start with the week that has at least four days in the new year
3 = vbFirstFullWeek − Start with the first full week of the new year
3 = vbFirstFullWeek − Start with the first full week of the new year
<!DOCTYPE html>
<html>
   <body>
      <script language = "vbscript" type = "text/vbscript">
         Dim Quarter, DayOfYear, WeekOfYear

         Date1 = "2013-01-15"
         Quarter    = DatePart("q", Date1)
         document.write("Line 1 : " & Quarter&"<br />")
         DayOfYear  = DatePart("y", Date1)
         document.write("Line 2 : " & DayOfYear&"<br />")
         WeekOfYear = DatePart("ww", Date1)
         document.write("Line 3 : " & WeekOfYear&"<br />")
         document.write("Line 4 : " & DatePart("m",Date1))

      </script>
   </body>
</html>
When you save it as .html and execute it in Internet Explorer, then the above script will produce the following result −
Line 1 : 1
Line 2 : 15
Line 3 : 3
Line 4 : 1 


    63 Lectures 
     4 hours 

 Frahaan Hussain
 Print
 Add Notes
 Bookmark this page