Copy Code code as follows:
<%
' Please keep this declaration information when forwarding, this statement does not affect your speed!
' ************************** ' Date extension class ' Ver 0.1.1********************************
' Developer: Sman, Net Fetch
' Development Date: 2005-11-11
' Version number: Ver 0.1.1
' Official website: http://www.sman.cn http://www.ad0.cn
' E-mail: huihui3030@126.com NetFetchStudio@163.com
' Daily Online qq:19341293 32050450
' Copyright Disclaimer: Copyright No, piracy does not investigate, the source code open, welcome piracy, welcome you to the official website to seek support.
' If there is any improvement, please forward or feedback to huihui3030@126.com, netfetchstudio@163.com,thanks!
' Detailed use of instructions or examples please see the download attachment or to the official site or email contact download!
'************************************************************************************
Class Datefunex
Private D_
Private Firstweekofyear_
Private Firstdayofweek_
Private Sub Class_Initialize ()
D_ = date () Default current date
Firstdayofweek_ = 2 ' vbmonday
Firstweekofyear_ = 1 ' starts from the week of January 1.
End Sub
' Attribute setdate date
Public Property Let Setdate (value)
On Error Resume Next
If IsNumeric (value) Then
Value = Cint (value)
If len (value) < 3 Then value = "M" & Right ("0" &value,2)
Value = value & "-1"
End If
D_ = cDate (value)
End Property
' attribute firstweekofyear the first week of the year (please refer to the VBS manual for detailed setting)
Public Property Let FirstWeekOfYear (value)
Firstweekofyear_ = cInt (value)
End Property
' attribute firstdayofweek the first day of the week (please refer to the VBS manual for detailed setting)
Public Property Let FirstDayOfWeek (value)
Firstdayofweek_ = cInt (value)
End Property
'------------------------------
' Function Description: What is the number of weeks of the week?
' Parameter description: Y year, W Week, Week week (Monday 1 days 7)
'------------------------------
Public Function getweekdate (y, W, DayOfWeek)
Dim Newyearday
Newyearday = CDate (Y & "-1-1") ' New Year's Day
Getweekdate = ((Newyearday-weekday (Newyearday, Firstdayofweek_)) + (w-1) * 7 + DayOfWeek)
End Function
'------------------------------
' Function Description: Get the number of days of a certain month
'------------------------------
Public Function Getmonthdaycount ()
Getmonthdaycount = DateDiff ("D", D_, DateAdd ("M", 1, D_))
End Function
'------------------------------
' Function Description: Get the first day of the month of a certain year
'------------------------------
Public Function Getmonthfirstday ()
Getmonthfirstday = CDate (Year (d_) & "-" & Month (D_) & "-1")
End Function
'------------------------------
' Function Description: Get the last day of the month of a certain year
'------------------------------
Public Function Getmonthlastday ()
Getmonthlastday = CDate (Year (d_) & "-" &month (d_) & "-" & DateDiff ("D", D_, DateAdd ("M", 1, D_))
End Function
'------------------------------
' Function Description: Date of the first day of the week in which the day is located
'------------------------------
Public Function Weekfirstday ()
Weekfirstday = Getweekdate (D_), DatePart ("ww", D_,firstdayofweek_,firstweekofyear_), 1)
End Function
'------------------------------
' Function Description: the date of the last day of the week on which the day is located
'------------------------------
Public Function Weeklastday ()
Weeklastday = Getweekdate (D_), DatePart ("ww", D_,firstdayofweek_,firstweekofyear_), 7)
End Function
End Class
%>
Test page:
Copy Code code as follows:
<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<% Option Explicit%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title>Test_clsDateFunEx</title>
<body>
<!--#include file= "clsdatefunex.asp"-->
<%
Dim mydatefun,strdate
strdate = "2005-4-1"
Set Mydatefun = new Datefunex
Mydatefun.setdate = strdate
Response.Write "2006 the 2nd week of Monday is the date:" & _
Mydatefun.getweekdate (2006,2,1) & "<br>"
Response.Write "April 2005 days:" &_
Mydatefun.getmonthdaycount & "<br>"
Response.Write "The first day of April 2005:" &_
Mydatefun.getmonthfirstday & "<br>"
Response.Write "The Last Day of April 2005:" &_
Mydatefun.getmonthlastday & "<br>"
Response.Write "date of the first day of the week of April 1, 2005:" &_
Mydatefun.weekfirstday & "<br>"
Response.Write "The date of the last day of the week of April 1, 2005:" & _
Mydatefun.weeklastday & "<br>"
Set Mydatefun = Nothing
%>
<br><br><br>
</body>
Download this file