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
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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

$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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.