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

Add days to a date in a grid

Status
Not open for further replies.

Holm78

Programmer
Joined
Mar 5, 2002
Messages
60
Location
SE
I have a grid
The first column contains DATE.
I would like some help. I need a way to change the date in the datecolumn. I need to add 1 day, 7 days or 30 days.
I was thinking to put buttons in the grid, one column for each. But maybe ther is a better way?

//Michael
 
Michael,
I suppose push buttons work okay. I'm not sure if you're asking this part or not, but in order to increase the number of days, simply do:

ldMyDATE = ldMyDate+1
or
ldMyDate = DATE()+1
or
ldMyDate = DATE()+7

if you want to move a "Real" month, instead of adding "30", since diffent months have different numbers of days, instead use

ldMyDATE = GOMONTH(DATE(),1)
which will add 1 month to the date.

Best Regards,
Scott

Please let me know if this has helped [hammer]
 
Hi scott!

I tried to put this code into the button in the grid

MyDate = GOMONTH(DATE(),1)

And when I clicked the button nothing happend not even a errror msg, and I checked the tabel and there where no uppdate.

//Michael
 
Holm,
Well, you need to make the value "MyDate" equal to the name of the field you are changing. (Sorry if I didn't make that clear...) Since you're in a grid, hopefully you are using as the control source, the actual field. Then, when us issue TABLEUPDATE(), it will save your change to the value.
Also, if there is a value in that field, and you want to advance it's date, you would do the following:

(Assume the date field is called SOMEDATE)

SOMEDATE = GOMONTH(SOMEDATE,1)

That should update the value directly in your grid, when you have the current row in the grid selected. Make sure you have a row in the grid selected, or nothing will happen when you click the button.
Best Regards,
Scott

Please let me know if this has helped [hammer]
 
To change the field in the table, you need to use REPLACE:
[tt]
SELECT myTable
REPLACE Date WITH GOMONTH(Date,1)
[/tt]
Substitute your table name for "myTable" and the actual date field for "Date" in both places. This will take the current value of "Date" and add 1 month to it.

Ian
 
Hi Ian

SELECT MyTable
REPLACE MyDate WITH gomonth(MyDate,1)
thisform.grid1.refresh

I use this code in a command button and I view the records in a Grid. When I press the button it adds 1 month to the record as shown in the grid but when I close the form and then open it again the date is back to it's old value.
It's like it doesn't save my change.

plz help

//Holm
 
HI HOlm,
If you are using buffering, then after the REPLACE code you put the code..
=TABLEUPDATE()
Hope this solves your problem :-) ramani :-9
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top