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

Previous month date range?

Status
Not open for further replies.

montypython1

Technical User
Jan 12, 2005
187
US
Greetings,

How to set dates to the first day and the last day of PREVIOUS month? (I am able to set dates to the first day and the current day of CURRENT month).

Thank you,
Dave
 
Here are a few date functions for you if you need more
Code:
*-------------------------
FUNCTION ISLEAPYR
*-------------------------
PARAMETER tdDate
tdDate = ChkParm(tdDate)
RETURN DAY(GOMONTH(tdDate +29 - DAY(tdDate), 2-MONTH(tdDate))) = 29

*-----------------------
FUNCTION DAYSINMO
*-----------------------
PARAMETER tdDate
tdDate = ChkParm(tdDate)
RETURN DAY(GOMONTH(tdDate+1 - DAY(tdDate),1) - 1)

*----------------------
FUNCTION LastDay
*----------------------
PARAMETER tdDate
tdDate = ChkParm(tdDate)
RETURN GOMONTH(tdDate +1 - DAY(tdDate),1) -1

*-------------------------
FUNCTION FirstDay
*-------------------------
PARAMETER tdDate
tdDate = ChkParm(tdDate)
return CTOD(ALLTRIM(STR(MONTH(tdDate))) + "/01/" + ALLTRIM(STR(YEAR(tdDate))))

*-----------------------
FUNCTION ChkParm
*----------------------
PARAMETER tdDate
return iif(vartype(tdDate) = 'D' AND !empty(tdDate),tdDate,date())

David W. Grewe Dave
 
One nice thing about VFP, there is always more then one way to skin a cat.


David W. Grewe Dave
 

Mike, and I like your leap year function.
I love short readable solutions.
 
Dave,
Use DATE() function when you want to convert something to DATE. What would happen if I have SET DATE GERMAN (like almost all East Europe has) and execute yourL
Code:
SET DATE GERMAN
? FirstDay(Date(2007,12,31)) && 12/31/2007 - Result: 01/12/2007


FUNCTION FirstDay
*-------------------------
PARAMETER tdDate
tdDate = ChkParm(tdDate)
return CTOD(ALLTRIM(STR(MONTH(tdDate))) + "/01/" + ALLTRIM(STR(YEAR(tdDate))))

But if you change it to:
Code:
FUNCTION FirstDay
*-------------------------
PARAMETER tdDate
tdDate = ChkParm(tdDate)
return DATE(YEAR(tdDate), MONTH(tdDate),1)
No matter what the date format is that function will return the right value.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
Microsoft MVP VFP
 
Thanks Borislav, None of my program ever run outside the USA so I never thought of it. Well on second Thought, I have some running in England and Australia.

David W. Grewe Dave
 
Thank you all!

Your suggestions worked perfectly!

Thanks,
Dave Higgins
 
Hi Dave:

"Thank you all!

Your suggestions worked perfectly!"


I think it is important that you issue a *, when solution is accepted or helped you get through the problem. It will help the readers to know that the problem is solved, and solution is available.

Also, it is not a good idea to issue a star when there is no solution, so others MVP could try to help solve the issue.

Thanks,



Nasib Kalsi









 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top