Jump to content

difference in time stamp


flemingmike

Recommended Posts

hello, im trying to figure out the difference between 2 numbers in minutes.  here is what i have:

 

$tsignin="09-05 10:30:00";
$tsignina="09-06 11:30:00";

$log_in_time_stringsa = strtotime($tsignin);
$log_out_time_stringsa = strtotime($tsignina);
$difference_in_secondssa = ($log_out_time_stringsa - $log_in_time_stringsa);
$tsigna = ($difference_in_secondssa / 60);
  
  $tsigna2 = number_format(round($tsigna));

 

the 09-05 is sept 5, and 09-06 is sept 6.

 

this works if the month and date are not included.  any ideas for me so i can figure out the total difference between date/times?

Link to comment
https://forums.phpfreaks.com/topic/246563-difference-in-time-stamp/
Share on other sites

To use strtotime() you must have a valid date string. "MM-DD HH:MM:SS" is not valid - what year is it? We know that you're talking about this year, but PHP doesn't know that.

$tsignin = "2011-09-05 10:30:00";

Where are these date/times coming from? Why don't they have years?

i was just taking a few different fields and making the timestamp.  i have now made it include the year and it is almost working.  it is giving me the difference in time, but not days.  im getting a difference on 60minutes.  is there a different way to do this so the whole timestamp gets subtracted?

$tsignin="2011-09-05 10:30:00";
$tsignina="2011-09-06 11:30:00";

$log_in_time_stringsa = strtotime($tsignin);
$log_out_time_stringsa = strtotime($tsignina);
$difference_in_secondssa = ($log_out_time_stringsa - $log_in_time_stringsa);
$tsigna = ($difference_in_secondssa / 60);
  
  $tsigna2 = number_format(round($tsigna));

echo "Logged in for {$tsigna2} minutes";

Logged in for 1,500 minutes

Works for me...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.