Jump to content

get second between two datetime


peterjc

Recommended Posts

 

If have two datetime.  so, i want to get the number of second between those two datetime.  How should i do it?

 

Example:

 

datetime 1 - start time: 2008-7-30 13:12:10

 

datetime 2 - end time: 2008-7-30 14:05:30

 

so, should be end time minus start time, but how to get it in second?

 

 

Thank in advance.

Link to comment
https://forums.phpfreaks.com/topic/117367-get-second-between-two-datetime/
Share on other sites

I think that is not what i want!  I just want to get the second between to date time.

 

Example:

datetime 1 - start time: 2008-7-30 13:10:10

datetime 2 - end time:  2008-7-30 13:15:10

 

Above example, the number of second should be 300 second right?

 

300 second is what i want.

 

Thank.

Oh, I thought you were using linux timestamps to store times, not these mysql timestamps you showed originally... I suppose that should have been obvious but I didn't see it.

 

<?php
echo strtotime('2008-7-30 13:15:10') - strtotime('2008-7-30 13:10:10');
?>

 

or for the current time minus a timestamp

 

<?php
echo time() - strtotime('2008-7-30 13:10:10');
?>

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.