>>>Is there a quick way to find the last date in any given month. I need to select records that fall within the selected month and year. I was going to use the between() command but how can you select the last date of a month (28,30,31) without lines of code?
>>
>>? LastDay(DATE())
>>? LastDay(DATE(), .t.)
>>
>>
>>FUNCTION LastDay(ldDate, lbDateWant)
>> LOCAL ldLastDay
>> ldLastDay = GOMONT(ldDate,1)-DAY(ldDate)
>>RETURN IIF(lbDateWant, DAY(ldLastDay), ldLastDay)
>>
>
>Doesn't work when your ldDate is January, March, May, August or October 31st, and probably also on last 2-3 days of January, because GoMonth() gives you the last of the next month in such cases.
>
>I'd prefer
>
>
gomonth(date(year(ldDate), month(ldDate), 1),1)-1
>
>i.e. find first of the month, from that the first of the next month, go back one day.
OOOPPPPSSSSS!
HUGE MISTAKE!
I am sorry Jim (Thank you Dragan)
FUNCTION LastDay(ldDate, lbDateWant)
LOCAL ldLastDay
LOCAL ldNextMonthDate
ldNextMonthDate = GOMONT(ldDate,1)
ldLastDay = ldNextMonthDate-DAY(ldNextMonthDate)
RETURN IIF(lbDateWant, DAY(ldLastDay), ldLastDay)
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.