View Full Version : Help with date math
mrsam5266
10-20-2011, 01:45 PM
This is probably a very simple question but I am struggling with some date math in PHP.
I have a variable $subscriptionDate that I need to increment by 92 days.
I have tried both strtotime and mktime but haven't been able to get the value I need.
Anybody got an idea?
Jason Byrnes
10-20-2011, 01:53 PM
well, what is the value of $subscriptionDate variable, we really need to know the value stored in the variable to be able to give a working solution.
use:
<?php echo($subscriptionDate); ?>
to output the value of the variable, from there we can tell you how to increment it 92 days
mrsam5266
10-20-2011, 03:06 PM
$subscriptionDate is a date value retrieved from a database table. Its format is yyyy-mm-dd hh:mm:ss
The time is irrelevant for my needs.
I've been playing with the code you showed me the other day but couldn't seem to get the variable to fit in it so things worked.
<?php date("Y-m-d, mktime(0,0,0,date("Y"),date("m"),date("d")+90)); ?>
Jason Byrnes
10-20-2011, 07:12 PM
here you go
<?php echo(date("Y-m-d h:i:s", mktime(date("h", strtotime($subscriptionDate)), date("i", strtotime($subscriptionDate)), date("s", strtotime($subscriptionDate)), date("m", strtotime($subscriptionDate)), date("d",strtotime($subscriptionDate))+90, date("Y", strtotime($subscriptionDate))))); ?>
vBulletin® v3.8.1, Copyright ©2000-2012, Jelsoft Enterprises Ltd.