Jul
04
2002
ASP date function wrappers
Posted by admin under
Daterelated functions
Here I will show you some routines on how to extract a part of a date, for example the month number of today. Hey, nothing new with that, right? 'I know those routines already are there, hmm something with datepart I think' you might think? Well, I to there are two problems with the VB script date functions: So hard to remember the somewhat obscure syntax ( like datepart("m", Now() ) for current month number and datepart("yyyy", Now() ) for current year number. The second problem is it takes so long to look it up. Therefore I have my own wrapper functions ( together with some other date functions - like show all months in a list etc ) in my own includefile: dateinc.asp. Easy to lookup and it allows me to call those functions what I want ( ( since I am an old C++-programmer actually ).
Here are the functions in my dateinc.asp:
<%
Function Date_GetYear( dDate )
Date_GetYear = DatePart( "yyyy", dDate )
End Function
%>
Returns a simple year number from a date, like
Date_GetYear( Now() ) gets current year
Date_GetYear( "8/3/1972" ) return 1972
<%
Function Date_GetMonthNo( dDate )
Date_GetMonthNo = DatePart( "m", dDate )
End Function
%>
<%
Function Date_GetDayNo( dDate )
Date_GetDayNo = DatePart( "d", dDate )
End Function
%>
<%
Function Date_GetMonthName( nMonthNo )
Select Case nMonthNo
Case 1
Date_GetMonthName = "Jan"
Case 2
Date_GetMonthName = "Feb"
Case 3
Date_GetMonthName = "Mar"
Case 4
Date_GetMonthName = "Apr"
Case 5
Date_GetMonthName = "May"
Case 6
Date_GetMonthName = "Jun"
Case 7
Date_GetMonthName = "Jul"
Case 8
Date_GetMonthName = "Aug"
Case 9
Date_GetMonthName = "Sep"
Case 10
Date_GetMonthName = "Oct"
Case 11
Date_GetMonthName = "Nov"
Case 12
Date_GetMonthName = "Dec"
End Select
End Function
%>