 |
| Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 4th, 2003, 12:25 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Days in a Month
Is there a function I can use to get the number of days in a month?
Let's say a user enters a date 01/23/2003, how can I tell that the month has 31 days without going through all the coding and validation of what month it is?
Thanks,
Judy
|
|

August 4th, 2003, 08:00 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
Judy,
I don't know if there is an inbuilt function for this but you can use something like
function daysInMonth(dateIn)
dim startDate, endDate
startDate = year(dateIn) & "/" & month(dateIn) & "/1"
endDate = year(dateIn) & "/" & month(dateIn) + 1 & "/1"
daysInMonth = dateDiff("d",startDate,endDate)
end function
Rod
======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
|
|

April 11th, 2005, 03:19 AM
|
|
Registered User
|
|
Join Date: Apr 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
This is better way of doing as the earlier function
function daysInMonth(dateIn)
dim startDate, endDate
startDate = year(dateIn) & "/" & month(dateIn) & "/1"
endDate = year(dateIn) & "/" & month(dateIn) + 1 & "/1"
daysInMonth = dateDiff("d",startDate,endDate)
end function
would fail if the month for which you want the number of days is December
So here I am using the inbuilt dateadd function that would generate the next month.
function daysInMonth(dateIn)
dim startDate, endDate
startDate = year(dateIn) & "/" & month(dateIn) & "/1"
endDate = dateadd("m",1,startDate)
daysInMonth = dateDiff("d",startDate,endDate)
end function
|
|

April 11th, 2005, 05:57 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
This may be a bit of a curve ball; I dont let users enter dates, I give them a pop up calendar to choose dates. There are many benefits to this, in particular - what format is the user going to enter vs the format you are looking for...
Wind is your friend
Matt
|
|
 |