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

date functions - number of days in a month 1

Status
Not open for further replies.

MrFancyteeth

Programmer
Mar 18, 2003
90
GB
hello

is there a function that returns the number of days in a month?



 
Func NumOfDays(dDate)
return gomonth(dDate - day(dDate) + 1, 1) - 1
endfunc


Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
No not natively, but this seems to work:
Code:
Function DaysInMonth
LPARAMETERS p_dDate && any valid day in month interested in

ldFirstOfMonth = DATE(YEAR(p_dDate), MONTH(p_dDate), 1)
ldFirstOfNextMonth = GOMONTH(ldFirstOfMonth, 1)
RETURN (ldFirstOfNextMonth - ldFirstOfMonth)
? DaysInMonth(DATE())
? DaysInMonth({^2003/02/27})
? DaysInMonth({^2000/02/27})

Rick
 
MrFancyteeth

Looks a little tricky but...(Put it all on one line)
Code:
nDays=(GOMONTH(CTOD("01"+SUBSTR(dtoc(DATE()),3,8)),1))-(GOMONTH(CTOD("01"+SUBSTR(dtoc(DATE()),3,8)),0))

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
** Correction *
Func NumOfDays(dDate)
return day(gomonth(dDate - day(dDate) + 1, 1) - 1)
endfunc


Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
Ali,
Yours returns the last day of the month, not the number of days - although with the DAY(NumOfDays(dDate)) it would work. (And it's still shorter than mine!)

Mike,
Yours can be dependent on the current SET DATE function, so it's not as universal.

MrFancyteeth,
Now you've got a number of choices!

Rick
 
Rick
I did post the modification.. Good looking out ;)



Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
Wow - many good answers

went with TeknoSDS's answer because of the concisiveness (is that a word?) - hence the star

Mr Fancyteeth
 
Rick

Yours can be dependent on the current SET DATE function, so it's not as universal.

How many times am I going to write this as a suggestion, before I learn my lesson. [curse]



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike,
As I may have said before, the only reason I'm so sensitive to it, is that I've been burnt once to often myself. Failure and debugging are the best "teacher"!

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top