I have a question on how to manipulate timestamps in PHP. Right now I have 2 seperate ones in the tools I'm writing. The first is recorded when a record is inserted into the system, and the second is a timestamp of the current date.
What I want to do is find the time difference between these 2 stamps and display it in a readable format. EX:
1 days 3 hours 34 mins
This would be displaying the time a record has been in the system.
Is there a way to do this??
timestamp questions
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Timestamps are just a count in seconds of the time since the UNIX epoch, so to get the difference between two you need to subtract one from the other and then you can use this bit of code which came from the PHP manual page on mktime():
Obviously you'll need to cater the code to your own needs.
Mac
Code: Select all
<?php
$now = mktime();
$before = mktime(0, 0, 0, 2, 10, 2003);
echo '$now: '.$now;
echo '<br />';
echo '$before: '.$before;
$seconds = ($now-$before);
$edays = floor($seconds / 86400); // get days
$ehours = floor(($seconds % 86400) / (3600)); // get hours
$emins = floor((($seconds % 86400) % 3600) / 60); // get mins
$esecs = floor((($seconds % 86400) % 3600) % 60); // get secs
echo 'Total Seconds: '.$seconds;
echo '<br />';
echo 'Days: '.$edays.' - Hours: '.$ehours.' - Minutes: '.$emins.' - Seconds: '.$esecs;
?>Mac