Adding 30 minutes to time formatted as H:i in PHP
$time = strtotime(’10:00′); $startTime = date(“H:i”, strtotime(‘-30 minutes’, $time)); $endTime = date(“H:i”, strtotime(‘+30 minutes’, $time));
$time = strtotime(’10:00′); $startTime = date(“H:i”, strtotime(‘-30 minutes’, $time)); $endTime = date(“H:i”, strtotime(‘+30 minutes’, $time));
First. You have mistake in using function strtotime see PHP documentation int strtotime ( string $time [, int $now = time() ] ) You need modify your code to pass integer timestamp into this function. Second. You use format d.m.Y H:i that includes time part. If you wish to compare only dates, you must remove … Read more
If you are using MySQL you can do it like this: SELECT ‘2008-12-31 23:59:59’ + INTERVAL 30 MINUTE; For a pure PHP solution use strtotime strtotime(‘+ 30 minute’,$yourdate);
Have a look at the DateTime class. It should do the calculations correctly and the date formats are compatible with strttotime. Something like: $datestring=’2011-03-30 first day of last month’; $dt=date_create($datestring); echo $dt->format(‘Y-m’); //2011-02
strtotime can be used to to quickly chop off the hour/minutes/seconds $beginOfDay = strtotime(“today”, $timestamp); $endOfDay = strtotime(“tomorrow”, $beginOfDay) – 1; DateTime can also be used, though requires a few extra steps to get from a long timestamp $dtNow = new DateTime(); // Set a non-default timezone if needed $dtNow->setTimezone(new DateTimeZone(‘Pacific/Chatham’)); $dtNow->setTimestamp($timestamp); $beginOfDay = clone … Read more
Change it to this will give you the expected format: $effectiveDate = date(‘Y-m-d’, strtotime(“+3 months”, strtotime($effectiveDate)));
Use DateTime $datetime = new DateTime(‘tomorrow’); echo $datetime->format(‘Y-m-d H:i:s’); Or: $datetime = new DateTime(‘2013-01-22’); $datetime->modify(‘+1 day’); echo $datetime->format(‘Y-m-d H:i:s’); Or: $datetime = new DateTime(‘2013-01-22’); $datetime->add(new DateInterval(“P1D”)); echo $datetime->format(‘Y-m-d H:i:s’); Or in PHP 5.4+: echo (new DateTime(‘2013-01-22’))->add(new DateInterval(“P1D”)) ->format(‘Y-m-d H:i:s’);
$futureDate=date(‘Y-m-d’, strtotime(‘+1 year’)); $futureDate is one year from now! $futureDate=date(‘Y-m-d’, strtotime(‘+1 year’, strtotime($startDate)) ); $futureDate is one year from $startDate!