This topic is locked
[SOLVED]

 before edit - add 6 months to current date

1/19/2020 12:03:29 PM
PHPRunner General questions
M
mhollibush author

I am looking for a resolution to this:
I have a date field that needs to update to 6 months from current date.
What do I put in the "before record updated" to update the date field to add 6 months from the current date.?
Little confused on some of the articles I have read..
Any help would be greatly appreciated.

lefty 1/19/2020



I am looking for a resolution to this:
I have a date field that needs to update to 6 months from current date.
What do I put in the "before record updated" to update the date field to add 6 months from the current date.?
Little confused on some of the articles I have read..
Any help would be greatly appreciated.


Try Something like this:
[font="Consolas,"]
[font="Consolas,"]
[font="Consolas,"]

M
mhollibush author 1/19/2020

Thanks for the reply,
I have tried the following:



$values["end_date"]=date("d/m/y", strtotime('+6 months'));




$values["end_date"]=date("dd/mm/yyyy", strtotime('+6 months'));




$values["end_date"]=date("YYYY-MM-DD", strtotime('+6 months'));




$values["end_date"]=date("yyyy-mm-dd", strtotime('+6 months'));


No matter which format I use, it doesn't update or store the data

as per PHPmyAdmin - the stored format is YYYY-MM-DD
The field it setup as DATE
I should specify - I am trying to save "now() + 6 months"....

I have read several different articles, and have tried numerous things... but it never saves the data.... but also not giving any errors

M
mhollibush author 1/19/2020

Figured This Out



$values["end_date"]=date('Y-m-d', strtotime("+180 days"));


This adds 6 months on to the current date.

lefty 1/19/2020



Figured This Out



$values["end_date"]=date('Y-m-d', strtotime("+180 days"));


This adds 6 months on to the current date.


Glad you got what you needed although I would test as days may be off in the long run ex... leap year . I always went to months as PHP newer version knows how many days are in each month. Depends on what results you expect? ( Unix Timestamp )

M
mhollibush author 1/20/2020



Glad you got what you needed although I would test as days may be off in the long run ex... leap year . I always went to months as PHP newer version knows how many days are in each month. Depends on what results you expect? ( Unix Timestamp )


Will check it out.... didn't think about leap year :/