note 108331 added to function.date-diff

From: Date: Tue, 17 Apr 2012 22:29:32 +0000
Subject: note 108331 added to function.date-diff
Groups: php.notes 
Request: Send a blank email to php-notes+get-187211@lists.php.net to get a copy of this message
Other data_diff aviable for php5.3>= <?php // Author: el pinche <fitorec> function otherDiffDate($end='2020-06-09 10:30:00', $out_in_array=false){ $intervalo = date_diff(date_create(), date_create($end)); $out = $intervalo->format("Years:%Y,Months:%M,Days:%d,Hours:%H,Minutes:%i,Seconds:%s"); if(!$out_in_array) return $out; $a_out = array(); array_walk(explode(',',$out), function($val,$key) use(&$a_out){ $v=explode(':',$val); $a_out[$v[0]] = $v[1]; }); return $a_out; } ?> #example 1 <?php echo otherDiffDate(); ?> out1 Years:08,Months:01,Days:22,Hours:17,Minutes:5,Seconds:26 example2 <?php print_r(otherDiffDate('2020-01-01 20:30:00',true)); ?> out2 Array ( [Years] => 07 [Months] => 08 [Days] => 15 [Hours] => 03 [Minutes] => 3 [Seconds] => 48 ) ---- Server IP: 69.147.83.197 Probable Submitter: 187.171.208.176 ---- Manual Page -- http://www.php.net/manual/en/function.date-diff.php Edit -- https://master.php.net/note/edit/108331 Del: integrated -- https://master.php.net/note/delete/108331/integrated Del: useless -- https://master.php.net/note/delete/108331/useless Del: bad code -- https://master.php.net/note/delete/108331/bad+code Del: spam -- https://master.php.net/note/delete/108331/spam Del: non-english -- https://master.php.net/note/delete/108331/non-english Del: in docs -- https://master.php.net/note/delete/108331/in+docs Del: other reasons-- https://master.php.net/note/delete/108331 Reject -- https://master.php.net/note/reject/108331 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#187211) next »