So what I need to do is add 30 minutes to the following
date["Ymdhis"];
I tried this
+strtotime["+30 minutes"];
however it does not seem to like it. I wondering what the correct why to do this is.
asked Mar 22, 2012 at 22:47
RussellHarrowerRussellHarrower
6,39121 gold badges94 silver badges188 bronze badges
1
Your method of using strtotime
should work.
Output
2012/03/22 10:55:45
2012/03/22 11:25:45 // 30 minutes later
However your method of adding time probably isn't correct. The above will work to add 30 minutes to the current time. Suppose you want to add 30 minutes from a given time, $t
, then use strtotime
's second parameter, which is used as a base for the calculation of relative dates.
date["Y/m/d H:i:s", strtotime["+30 minutes", $t]];
//codepad.org/Z5yquF55
answered Mar 22, 2012 at 22:56
I tested this code but it doesn't work for me:
$t = date[];
date["Y/m/d h:i:s", strtotime["+30 minutes", $t]];
Here's my solution
//This is where you put the date, but I use the current date for this example
$date = date["Y-m-d H:i:s"];
//Convert the variable date using strtotime and 30 minutes then format it again on the desired date format
$add_min = date["Y-m-d H:i:s", strtotime[$date . "+30 minutes"]];
echo $date . "
"; //current date or whatever date you want to put in here
echo $add_min; //add 30 minutes
answered Mar 23, 2012 at 5:38
SuperNoobSuperNoob
3723 silver badges6 bronze badges
strtotime[]
accepts a second parameter which is its starting point.
If you have date["Ymdhis", $somedate]
and wanted to add 30 minutes to it, you can do date["Ymdhis", strtotime["+30 minutes", $someddate]]
answered Mar 22, 2012 at 22:57
staticsanstaticsan
29.4k4 gold badges58 silver badges73 bronze badges
Try something like.
$Start = "12:00:00";
$Minutes = 30;
$To = date["H:i:s", strtotime[$Start]+[$Minutes*60]];
answered Mar 22, 2012 at 22:51
AdamAdam
3,5336 gold badges30 silver badges50 bronze badges
Use this function:
date["Ymdhis", strtotime["+30 minutes"]]
Somnath Muluk
52.5k34 gold badges216 silver badges224 bronze badges
answered Mar 22, 2012 at 22:57
sikandersikander
2,31316 silver badges23 bronze badges
Not sure what your entire code looks like, but:
date["Ymdhis"];
is returning a string. So it doesn't make sense to add the result of
strtotime["+30 minutes"];
[which is an integer] to that string.
You either want
strtotime["+30 minutes"];
by itself, or
date["Ymdhis", strtotime["+30 minutes"]];
to get the formatted string.
answered Mar 22, 2012 at 22:56
mattmatt
1,9281 gold badge20 silver badges28 bronze badges
1
Do you mean date["Ymdhis", strtotime["+30 minutes"]];
? This will represent the date that is 30
minutes in the future.
answered Mar 22, 2012 at 22:57
mvdnesmvdnes
3831 silver badge5 bronze badges
answered Mar 22, 2012 at 23:05