In asp, we need to get the total number of days in a certain year. We mainly use the DatePart function in asp to copy the code as follows:
'Returns the total number of days in a certain year
Function DayOfYear(ByVal y)
DayOfYear = DatePart(y,y&-12-31)
End Function5
'Example: Response.Write DayOfYear(2012)
Detailed syntax of Asp DatePart function
DatePart(interval, date[, firstdayofweek[, firstweekofyear]])
The syntax of the DatePart function has the following parameters:
Parameter description
interval is required. A string expression representing the time interval to return. See the Settings section for numerical values.
date is required. The date expression to evaluate.
firstdayof week optional. A constant that specifies the first day of the week. If not specified, it defaults to Sunday. See the Settings section for numerical values.
firstweekofyear Optional. Constant that specifies the first week of the year. If not specified, it defaults to the week of January 1st. See the Settings section for numerical values.
The interval parameter can be set to the following values:
Setting description
yyyy year
q quarter
m month
y the number of days in a year
d day
w Day of the week
ww weeks
h hours
m minutes
s seconds
The firstdayofweek parameter can have the following values:
Constant value description
vbUseSystem 0 Use the National Language Support (NLS) API setting.
vbSunday 1 Sunday (default)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday
The firstweekofyear parameter can have the following values:
Constant value description
vbUseSystem 0 Use the National Language Support (NLS) API setting.
vbFirstJan1 1 Starts with the week of January 1st (default).
vbFirstFourDays 2 starts with the first week of the new year that has at least four days.
vbFirstFullWeek 3 starts with the first full week of the new year (not across years).
illustrate
The DatePart function calculates a date and returns a specified time interval. For example, use DatePart to calculate the day of the week or the current time on a certain day.
The firstdayofweek parameter affects calculations using w and ww interval symbols.
If date is a date literal, the specified year becomes a fixed part of the date. But if the date is enclosed in quotation marks ( ) and the year is omitted, the current year will be inserted every time the date expression is evaluated in the code. This makes it possible to write program code that works for different years.