dateinterval

Are PHP DateInterval comparable like DateTime?

被刻印的时光 ゝ 提交于 2019-11-26 18:25:23
问题 I discovered that a DateTime object in PHP can be compared to another as the ">" and "<" operators are overloaded. Is it the same with DateInterval? As I was trying to answer this question, I found something strange: <?php $today = new DateTime(); $release = new DateTime('14-02-2012'); $building_time = new DateInterval('P15D'); var_dump($today->diff($release)); var_dump($building_time); var_dump($today->diff($release)>$building_time); var_dump($today->diff($release)<$building_time); if($today

php Object of class DateInterval could not be converted to string

送分小仙女□ 提交于 2019-11-26 17:23:06
问题 i've tried using date_diff and date_create to get a difference from two date that's already converted to string. here's the code: $date_1 = date_create(); $date_now = date_format($date_1, 'Y-m-d'); //echo $date_now . "\n"; $date=date_create($date_now); date_add($date,date_interval_create_from_date_string("3 days")); $date_return = date_format($date,"Y-m-d"); $diff = date_diff(date_create($date_now), date_create($date_return)); echo $diff; and i am getting this error: Object of class

How we can add two date intervals in PHP

时光总嘲笑我的痴心妄想 提交于 2019-11-26 11:24:56
i want to add two date intervals to calculate the total duration in hours and minutes in fact i want to perform addittion as shown below: $a = new DateTime('14:25'); $b = new DateTime('17:30'); $interval1 = $a->diff($b); echo "interval 1 : " . $interval1->format("%H:%I"); echo "<br />"; $c = new DateTime('08:00'); $d = new DateTime('13:00'); $interval2 = $c->diff($d); echo "interval 2 : " . $interval2->format("%H:%I"); echo "<br />"; echo "Total interval : " . $interval1 + $interval2; Any idea how to perform this type of interval addition to get the sum of the two intervals in total hours and

How we can add two date intervals in PHP

旧巷老猫 提交于 2019-11-26 02:24:56
问题 i want to add two date intervals to calculate the total duration in hours and minutes in fact i want to perform addittion as shown below: $a = new DateTime(\'14:25\'); $b = new DateTime(\'17:30\'); $interval1 = $a->diff($b); echo \"interval 1 : \" . $interval1->format(\"%H:%I\"); echo \"<br />\"; $c = new DateTime(\'08:00\'); $d = new DateTime(\'13:00\'); $interval2 = $c->diff($d); echo \"interval 2 : \" . $interval2->format(\"%H:%I\"); echo \"<br />\"; echo \"Total interval : \" . $interval1