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

Replace field with GOMONTH date + one month 2

Status
Not open for further replies.

keepingbusy

Programmer
Apr 9, 2000
1,470
GB

Hi

Version 9

The following replaces a field in a table with the 1st day of the current month:
Code:
REPLACE MYFIELD WITH GOMONTH(DATE(), IIF(DAY(DATE())=1,1,0)) ;
- DAY(GOMONTH(DATE(), IIF(DAY(DATE())=1,1,0))-1)
The help file doesn't tell too much but I am trying to replace MYFIELD with +1 month and retain the 1st day.

So in other words, if the date was 01/06/2010 I would want the field replaced with 01/07/2010 or if one less -1 month.

These are british date formats (DD/MM/YYYY).

Any guidance would be appreciated.

Thank you
 

Hello Mike

I did try something similar before I posted this but that just returns the current month (e.g. 01/06/2010)

So basically I need to add a month or subtract a month (01/07/2010 or 01/05/2010).

Lee
 
Lee,

You're saying you want the first day of next month?

If so, my original suggestion should do that:

Code:
REPLACE MyField WITH ;
  GOMONTH(DATE(), 1) - DAY(GOMONTH(DATE(), 1)) + 1

So, today is 29th May. The above will return 1st June. Isn't that what you want?

You also want the first day of last month?

Code:
REPLACE MyField WITH ;
  GOMONTH(DATE(), -1) - DAY(GOMONTH(DATE(), -1)) + 1

This would give 1st April.

If that doesn't work, I must have misunderstoond the requirement.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Code:
n = -1 && previous month
n = 0 && this month
n = 1 && next month
? GOMONTH(DATE()-DAY(DATE())+1, m.n)

Cetin Basoz
MS Foxpro MVP, MCP
 
Mike

Yes, you are exactly right. Your code does produce the desired result. The actual scenario is that there could be a previous date such as 01/05/2010 which would be converted to the next month.

Thank you for your post.

Cetin
Code:
? GOMONTH(DATE()-DAY(DATE())+1, m.n)
This also achieves the desired effect and the explanation of the additional variables has been very useful.

Thank you for your post.

My appreciation to all

Lee

Visual FoxPro Version 9
Windows 7
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top