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

Foxpro 2.6 DATE Return first and last day of month 1

Status
Not open for further replies.

jlg13

Technical User
May 10, 2001
61
US
Hi,

I could use some help with dates.

I have set m.date to a date in this format mm/dd/yyyy

Now I want to create 2 new variables stadate & enddate where stadate is the first day of the month and enddate is the last day of the month associated with m.date.

Example
m.date = 05/15/2019

I would like

stadate = 05/01/2019
enddate = 05/31/2019

2nd Question How do I then modify enddate to return a date 1 year later (05/31/2020)


Thank you for your time.

Joe




 
Since I don't have an idea when certain date functions were introduced, can you run each of these separately and tell us if the work and what they result in?

1. Don't set a variable to a string, but to a date:
Code:
? {^1999-12-31}
? Date(1999,12,31)
? Date()
? Date()+1
? Date()-1
? GoMonth(Date(),1)
? GoMonth(Date(),12)
? Year(Date())
? Month(Date()
? Day(Date())
? DToC(Date())
? CToD('12/31/1999')
? CToD('31/12/1999')

Bye, Olaf.

Olaf Doschke Software Engineering
 
Hi Olaf,

First, thanks for being so fast with replies. Very appreciated as I am in the code now.

Second, thanks for the replies to my post about keeping foxpro 2.6 running beyond MS Server 2008. I still have to dig into that information, its a bit above my knowledge level :)

I am running your command statements now. Will reply back shortly.

Joe
 
? {^1999-12-31} = / /
? Date(1999,12,31) = too many arguments
? Date() = 07/07/2019
? Date()+1 = 07/08/2019
? Date()-1 = 07/06/2019
? GoMonth(Date(),1) = 08/07/2019
? GoMonth(Date(),12) = 07/07/2020
? Year(Date()) = 2019
? Month(Date()) = 7
? Day(Date()) = 7
? DToC(Date()) = 07/07/2019
? CToD('12/31/1999') = 12/31/1999
? CToD('31/12/1999') = / /
 
OK, that looks quite good, some things are not available, but you can maybe already see what functionalities will help to calculate with dates.

First of all, it's important you can set your initial date in m.date as variable type date and not as a string, because you can't make date calculations with strings.

Since neither DATE() takes three parameters year, month, day nor you can specify a date in the way later VFP versions know it as literal {^yyyy-mm-dd}, you have to start from a string. You can use CTOD('mm/dd/yyyy') for that matter. It#s a bit unfortunate, as you see when date settings are differing from the string you get the empty date (just two slashes). String literals in curly brackets are interpreted in the same way always, no matter if your date settings are month/day or day/month.

All you need is this, obviously with some numbers for mm, dd, and yyyy:
Code:
m.date=CTOD('mm/dd/yyyy')
m.stadate = m.date-day(m.date)+1
m.enddate = GoMonth(m.stadate,1)-1

For today, simply set m.date=DATE()

Bye, Olaf.

Olaf Doschke Software Engineering
 
Olaf, you're the best! thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top