Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Find last date in a month
Message
 
To
22/01/2007 13:40:03
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01187758
Message ID:
01187771
Views:
16
>>>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())      && Just day
>>? LastDay(DATE(), .t.) && We want DATE
>>
>>
>>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.
Previous
Reply
Map
View

Click here to load this message in the networking platform