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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Days in a month 1

Status
Not open for further replies.

ashark

Programmer
Nov 21, 2002
31
0
0
IN
Hi Group,
Is there a function in crystal report which returns the number of days in a month if given a particular month and year.

For eg. if i input 01-2003 it should return 31
02-2000 then 29
02-2001 then 28...
Please tell me if there is a function?

Regards,
ashark



 
There isn't a built in function which does this, but you can write your own:

if month({DateField}) in [1,3,5,7,8,10,12] then 31
else if month({DateField}) in [4,6,9,11] then 30
else if remainder(Year({DateField}),400)= 0 then 29
else if remainder(Year({DateField}),100)= 0 then 28
else if remainder(Year({DateField}),4)= 0 then 29 else 28

Naith
 
Naith,

Please explain the last 3 lines of code.

Are you saying that the years 2100, 2200 and 2300 are not leap years? Software Sales, Training and Support for Macola, Crystal Reports and Goldmine
dgilsdorf@mchsi.com
 
Actually I was very curious on this and did some research and Naith is correct, if the year is perfectly divisible by 4 and perfectly divisible by 400, it is a leap year.

If the year is perfectly divisible by 4 and by 100, it is not a leap year. Otherwise all other years that are perfectly divisible by 4 are leap years.

Also, I found out that there is never a February 30th, which I was under the impression happened every 400 years. This is not likely anything I will ever have to worry about in my programming career. Software Sales, Training and Support for Macola, Crystal Reports and Goldmine
dgilsdorf@mchsi.com
 
dgillz,

That's what I tried pointing out in this thread (thread767-454997) when you posted the first, second and last lines of the formula above. I then added the "special condition" lines into your formula to make the formula that Naith borrowed from this thread (thread767-458252)

Mike
If you're not part of the solution, you're part of the precipitate.
 
Hey dgillz,

Sorry I left you to figure it out for yourself. (One of my production databases went awol.)

I'm not sure about the February 30th point, but you're right in your deduction that 2100, 2200, and other centenaries not divisible by 4 are not leap years. I do agree with your conclusion that this consideration is probably overkill in most cases, and freely own up to skipping this check in my own reports.

Naith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top