date - Calculating time differences in minutes (PHP) -


i want set timer , calculate how long takes task.

so have following php code set test:

$firstdate = date('y-m-d h:m:s'); sleep(80); $seconddate = date('y-m-d h:m:s'); $diffdates = (strtotime($seconddate) - strtotime($firstdate));  echo "difference in dates is:" . $diffdates . "\n"; 

when run though gives me following output:

    difference in dates is:-40 

what i'm wondering is, why give me -40, , how can set can simple calculation of ending date - starting date in minutes.

your appreciated.

the problem have time format string wrong:

$firstdate = date('y-m-d h:m:s');

the second m, should i 'minutes', 'month' again, 07

this fix it:

date('y-m-d h:i:s')

it's worth noting if use format should add a end designate am or pm, or use h in place of h 24 hour format.

this cause issues. example right 3:17 pm, when this:

echo time(); echo "<br>"; echo strtotime(date('y-m-d h:i:s')); 

my output is:

1501010231 1500967031 

but using date('y-m-d h:i:s a') or date('y-m-d h:i:s') give intended result of both values being identical.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -