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 Mike Lewis 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

Status
Not open for further replies.

dhv919401

Programmer
Apr 26, 2004
34
CA
How can we get days in a month, if the month number is given. I need a function as below:

DaysInAMonth(MonthNumber) = NumberofDaysInMonthNumber

Thank you,
 
You need to build in a year to account for leap years. Try:

day(dateserial(year({table.date}),month({table.date})+1,1)-1)

You could substitute your monthnumber for month({table.date}). If you are always basing it on the currentyear, substitute currentdate for {table.date}.

-LB
 
I do not have a date. I need to know based on the monthnumber. Like Days(1) = 31 days in January.
Is there anyway?
Thank you so much,
 
Create a formula similar to below

If month({CLIENT.CLI_UPD_DATE}) in [9, 4, 6, 11] then 30
else if month({CLIENT.CLI_UPD_DATE}) in [1, 3, 5, 7, 8, 10, 12] then 31
else
if month({CLIENT.CLI_UPD_DATE}) = 2 and isdate("Feb 29, "&totext(year({CLIENT.CLI_UPD_DATE}),0,"")) = true then 29 else 28

Replace date field with one of yours and save

right Click on Custom function and select new.
Give it a name eg NumberOfDays and select extractor

The above formula will be available to use. select it and function will build automatically. Save and then create a new formula.

In formula type function name NumberOfDays( Newdate field)

NumberOfDays will be blue to show its a function, place formula in details and it will return number of days.

Ian
 
You have to have a date somewhere, otherwise how will you know if its a leap year or not.

Ian
 
As I said, you could use:

day(dateserial(year(currentdate),monthnumber+1,1)-1)

This does assume the current year, however. You didn't clarify on that point.

-LB
 
Thank you so much. I have already built exactly the same way you mentioned. But I just wanted to confirm that there is a built-in function in Crystal to do this. May be it is worthy to have one in the later versions of Crystal.
Thank you for all your help,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top