DatePart Function

Tips >>ASP Functions

WANTS TO MAKE SOFTWARE WITHOUT KNOWLEDGE OF ASP? CLICK HERE

The DatePart function returns the specified part of a given date. A string expression that is the interval of time you want to return. See Settings section for values. Required. The date expression you want to evaluate. You can use the DatePart function to evaluate a date and return a specific interval of time. For example, you might use DatePart to calculate the day of the week or the current hour. The DatePart function returns the designated part of the date.

There are Two Mandatory Arguments :-

  • First day of week
    A constant that specifies the day of the week. If not specified, Sunday is assumed. See Settings section for values. Optional.

  • First week of year
    A constant that specifies the first week of the year. If not specified, the first week is assumed to be the week in which January 1 occurs. See Settings section for values. Optional.


The Syntax of DatePart function is :-

DatePart(interval,date[,firstdayofweek[,firstweekofyear]])

Its description is :-

Parameter Description
date Required. Date expression to evaluate
first day of week

Optional. Specifies the day of the week.
Can take the following values :·

  • 0 = vb Use System Day Of Week - Use National Language Support (NLS) API setting.
  • 1 = vbSunday - Sunday (default).
  • 2 = vbMonday - Monday.
  • 3 = vbTuesday - Tuesday.
  • 4 = vbWednesday - Wednesday.
  • 5 = vbThursday - Thursday.
  • 6 = vbFriday - Friday.
  • 7 = vbSaturday - Saturday
first week of year

Optional. Specifies the first week of the year. 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.

Example#1 :-

Code :-
document.write(Date & "<br />")
document.write(DatePart("d",Date))
Output :-
1/14/2002
14

Example#2 :-

Code :-
document.write(Date & "<br />")
document.write(DatePart("w",Date))
Output :-
1/14/2002
2

 

 
E-mail : sales@virtualsplat.com
Phone : +91-9892413501

Whatsapp Icon +91-9967648641

Whatsapp Icon +91-9967648641