
Good day,
I had a request from someone to add choices in the list of pre-defined date ranges. She asked me for something like "Last x Months" and "x Months ago [MonthName]", where x can vary from 2 to 6, "Current Month, Last Month and Last Month (Rolling)" being already available.
This is what I'm doing at this moment, however I noticed that the formula used to return the last day of a given month isn't right.
The formula, in the "Calendar.asp" file reads as follow :
intDaysInMonth = Day(DateAdd("d", 0 - Day(datCurrent), DateAdd("m", 1, datCurrent)))
For instance, it returned 30 days for May, and there should be 31.
I replaced it with the following :
intDaysInMonth = Day(DateAdd("d", -1, DateSerial(datYear, datMonth + 1, 1)))
Please verify if this "fix" is necessary for you version, simply by clicking on the calendar icon and confirming if it presents the proper amount of days.
For your information, the line to be fixed, at least in my case, was around line 50.
Note: There might be other ways to achieve a similar calculation, however the one suggested above has proven to be working for a quite a substantial period of time. I created it few years ago when I was doing a project with Access and VBA.
Regards.
Number of days in a given month
Hi Daniel,
It always returns the correct number of days for me (including May). I am using the default Session.LCID setting (1033), maybe this affects it somehow. What LCID are you using?
I re-examined the logic for the intDaysInMonth calculation and it should provide the same answer as the code you supplied.
Regards,
~Chad
Number of days in a given month
quote:Originally posted by cdegroot
Hi Daniel,
It always returns the correct number of days for me (including May). I am using the default Session.LCID setting (1033), maybe this affects it somehow. What LCID are you using?
I re-examined the logic for the intDaysInMonth calculation and it should provide the same answer as the code you supplied.
Regards,
~Chad
Chad, I'm also using LCID=1033 (English US).
For a reason which is unknown to me, I can swear I had 30 days shown on the screen for May, which left me a bit perplex.
Just for the sake of it, I disabled my fix, and re-enabled the code that was there before, and "surprisingly" everything is just fine with your code too.
I guess I'm rusting with VBScript instead of improving! :oops:
Sorry for the false alarm.
Regards.