note 108331 deleted from function.date-diff by danbrown

From: Date: Thu, 10 May 2012 17:09:01 +0000
Subject: note 108331 deleted from function.date-diff by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-187658@lists.php.net to get a copy of this message
Note Submitter: programacion at mundosica dot com ---- 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 )

« previous php.notes (#187658) next »