python - PHP array with datetime function to get time in seconds -


i have wrote function in python (as have solid knowledge there), need use function in php (on codeigniter project - model). question how fallowing function on php:

import datetime  datetime import timedelta  def getmaxvalverify(mylist):      intervaltime = mylist[len(mylist) -1][1] -  mylist[0][1]      seconds=timedelta.total_seconds(intervaltime)      return seconds

now explain does, list(array) looks :

list = [(41740, datetime.datetime(2016, 6, 20, 18, 00, 00)), (41280, datetime.datetime(2016, 6, 20, 18, 00, 30)), (40500, datetime.datetime(2016, 6, 20, 18, 02, 00))]

it return difference in seconds first datetime element last, in our case 18:00:00 18:02:00 return:

print getmaxvalverify(list)    120.0

you should use datetime class in php, gives access dateintervals.

example 2 dates :

<?php $datestart = new datetime('2016-06-20 18:00:00'); $interval= $datestart->diff(new datetime('2016-06-20 18:30:00')); echo $interval->s.' seconds'; 

function example :

<?php function getinterval($list) // although should use 2 parameters instead {     $datestartlist = min($list);     $dateendlist = max($list);      $datestart = new datetime(datestartlist);     $interval= $datestart->diff(new datetime($dateendlist));     return $interval->s }  echo getinterval('2016-06-20 18:00:00', '2016-06-20 17:20:00', '2016-06-20 18:30:00') . ' seconds'; 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -