Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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
 
Old August 4th, 2003, 12:25 PM
Friend of Wrox
Points: 1,035, Level: 12
Points: 1,035, Level: 12 Points: 1,035, Level: 12 Points: 1,035, Level: 12
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , USA.
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jmss66
Default 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
 
Old August 4th, 2003, 08:00 PM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

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.
======================================
 
Old April 11th, 2005, 03:19 AM
Registered User
 
Join Date: Apr 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old April 11th, 2005, 05:57 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

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




Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting month name to month number kalyanykk SQL Server 2005 7 August 19th, 2008 10:37 PM
Exact year month and days mankoti_mankoti2000 Access 1 July 3rd, 2008 10:05 AM
find days per month in a date range rojer MySQL 1 June 5th, 2007 07:36 PM
query Current Month, Month+1, Month+2, Month+3 anterior Access 2 September 24th, 2006 08:25 PM
No of days anandham SQL Server 2000 2 March 21st, 2005 01:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.