Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find out number of days in a month of a certain year

Status
Not open for further replies.

yu217171

Programmer
Joined
Aug 2, 2002
Messages
203
Location
CA
Hi everyone,

Is there a formula to calculate the number of days in a month, if I provide it the current date?

For instance, I pass the function today's date (April 15, 2004) and it will return 30 back to me.

It needs to work for every year and every month.

Thanks,
Keith
 
I also need to find out how to launch a script automatically based on the date. Can someone point me in the right direction?

Keith
 
This should work...

Public Function getNumberDaysInMonth(ByVal dteDate As Date) As Integer
Dim intMonth, intYear As Integer
Dim dteFirst As Date
intMonth = Format(dteDate, "MM")
intYear = Format(dteDate, "yyyy")
dteFirst = intMonth & "/1/" & intYear
getNumberDaysInMonth = DateDiff(DateInterval.Day, dteFirst, DateAdd(DateInterval.Month, 1, dteFirst))
End Function

I don't know about launching scripts automatically.
Hope this helps.

Hope everyone is having a great day!

Thanks - Jennifer
 
Great thnx Jenn. That's a nice function. I just used an array storing the values {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} and accounted for the leap years =)

Thanks,
Keith
 
Regarding launching scripts automatically. I found out that you could use the task scheduler. Schedule an Internet Explorer task and then in the advanced properties specific the webform that you want to launch as a parameter. (IEXPLORE.EXE C:\WEBFORM.ASPX) And you're away to the races.

For me, I used a javascript startup page for redirections to other scripts.

HTH anyone that wants to run tasks without user input.

Keith
 
This is actually pretty easy in .NET:
Code:
int DaysInMonth = DateTime.DaysInMonth(2004, 4);

If you're using a different calendar than the culture-insensitive one, or the one used by most of the western world, you'll get a different answer from this method call. For example, the Hebrew calendar calculates leap years differently than the Gregorian calendar (they have 13 months those years).

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Thanks, Chip.

Sadly, the scripts were written in classic ASP and I just needed an algorithm to do it. I didn't want to spend time porting code that someone else had written.

Thanks anyways.

Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top