Try this one then: (you can get rid of the stuff in BOLD BLUE if you won't be calcating a date before 1901 and after 2099 otherwise the special leap year rules apply
if mnth in [1,3,5,7,8,10,12] then dayout:=31 else
if mnth in [4,6,9,11] then dayout:=30 else if remainder(yr,400)=0 then dayout:=29 else
if remainder(yr,100)=0 then dayout:=28 else
if remainder (year,4)=0 then dayout:=29 else
dayout:=28;
if mnth in [1,3,5,7,8,10,12] then dayout:=31 else
if mnth in [4,6,9,11] then dayout:=30 else
if remainder(yr,400)=0 then dayout:=29 else
if remainder(yr,100)=0 then dayout:=28 else
if remainder (year,4)=0 then dayout:=29 else
dayout:=28;
Too dangerous for leap years in 2000 but not in 1900 or 2200. And while our reports may not be running then they will contain dates for those years now, or quite soon.
Try :
numbervar m:=month(currentdate)+1;
//change 1 to move forward or back a month
numbervar y:=year(currentdate);
if m>12 then (m:= m-12; y:=y+1); //Rollover past December
Date(y,m,1) -1
Works well for any years. Change the +1 to +4 and it will be the end of the month in four months time. Change it to -3 and it's 3 months ago.
If you go back a month you might need to add a line to check year rollover prior to Janaury.
if m<1 then (m:= m+12; y:= y -1); Editor and Publisher of Crystal Clear
If you want to use synapsvampire´s first suggestion with the DateAdd function date(year(dateadd("m",1,currentdate)), month(dateadd("m",1,currentdate)), 1)-1
Then you can download the UFL that handles it.
It will work for Crystal version 7.
Thanks for your wonderful responses. I am still having a problem with the dateadd function. The program recognizes the function but now it says "a date/time required here".
However the "if then formula" by mbarron improves my solution and I am happy with it.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.