note 102930 added to class.dateinterval

From: Date: Tue, 15 Mar 2011 14:07:12 +0000
Subject: note 102930 added to class.dateinterval
Groups: php.notes 
Request: Send a blank email to php-notes+get-177897@lists.php.net to get a copy of this message
If you want to convert a Timespan given in Seconds into an DateInterval Object you could dot the following: <?php $dv = new DateInterval('PT'.$timespan.'S'); ?> but wenn you look at the object, only the $dv->s property is set. As stated in the documentation to DateInterval::format The DateInterval::format() method does not recalculate carry over points in time strings nor in date segments. This is expected because it is not possible to overflow values like "32 days" which could be interpreted as anything from "1 month and 4 days" to "1 month and 1 day". If you still want to calculate the seconds into hours / days / years, etc do the following: <?php $d1 = new DateTime(); $d2 = new DateTime(); $d2->add(new DateInterval('PT'.$timespan.'S')); $iv = $d2->diff($d1); ?> $iv is an DateInterval set with days, years, hours, seconds, etc ... ---- Server IP: 85.214.154.209 Probable Submitter: 109.90.185.109 ---- Manual Page -- http://www.php.net/manual/en/class.dateinterval.php Edit -- https://master.php.net/note/edit/102930 Del: integrated -- https://master.php.net/note/delete/102930/integrated Del: useless -- https://master.php.net/note/delete/102930/useless Del: bad code -- https://master.php.net/note/delete/102930/bad+code Del: spam -- https://master.php.net/note/delete/102930/spam Del: non-english -- https://master.php.net/note/delete/102930/non-english Del: in docs -- https://master.php.net/note/delete/102930/in+docs Del: other reasons-- https://master.php.net/note/delete/102930 Reject -- https://master.php.net/note/reject/102930 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#177897) next »