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

finding End day of the Month 1

Status
Not open for further replies.

Halfcan

Technical User
Dec 8, 2002
214
US
Hello,
Does anyone know if there is a function in crystal that can determine that last day of a given month?
Im converting String values such as January, February,...
to months and getting the first day is no problem, but I having trouble calculating the last day.
THis is what I am using to find the 1st day of each month....
if {?MonthParam} = "January" then 01 else
if {?MonthParam} = "February" then 02 else
if {?MonthParam} = "March" then 03

Thanks
Andy
 
It would be difficult to provide foolproof logic as you don't specify a year, so leap years will be a problem.

You could add a bogus year value then use the dateadd function as below:

dateadd("d",-1,dateadd("m",1,date(2003,{@Month},01)))

where {@month} is the calculation you are already doing i.e. if "January" = 01 etc....

Let me know how you get on.......Enjoy!
Reebo
Scotland (Going mad in the mist!)
 
You could do the same thing for ending:

Jan = 31
Mar = 31
Apr = 30
etc

February is the only exception. However, if you know the year involved, and can calculate the first of March, you can simply subtract 1 from that to get either 28 or 29.

Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Expert's Guide to Formulas / Guide to Crystal in VB
- tek@kenhamady.com
 
Another approach is to use the month as the description, and the month number as the value, and select show description only in the parameter.

Now to determine the end of a month (assuming it's the current year), use:

dateadd("mm",1,year(currentdate),{?monthparmvalue},1)-1

This will add a month to whatever month was selected and subtract one day, hence the last day of the month selected.

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top