Jump to content


Photo

A small issue with Timestamps


  • Please log in to reply
1 reply to this topic

#1 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 20 October 2006 - 02:51 PM

Hey,
I am creating my clients ticket system, so they can submit tickets
and I wanted to have a duration, basicalyl stamps the time the user
sent their ticket / post, and When someone replys to it, it will take
the current time and subtract by the stamp which should leave the
in-between time...

1. I thought about using Strtotime(); to realise it would be much to
hard work, when timestamps are easier...
2. If i was to use timestamps how would i go about it?
Thx
Ash

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 20 October 2006 - 03:07 PM

when you say timestamps, are you referring to SQL timestamps (DATETIME), or are you referring to UNIX timestamps (via PHP)? they will be handled differently. i'll assume you mean a UNIX timestamp since you're talking about using it for calculations. basically, here's the premise:
<?php
function getDiff($start, $end) {
  $diff = abs($start - $end);
  $days = floor($diff / (60 * 60 * 24));
  $hours = floor(($diff % (60 * 60 * 24) / (60 * 60));
  $mins = floor((($diff % (60 * 60 * 24)) % (60 * 60)) / 60);
  return array('days' => $days, 'hours' => $hours, 'mins' => $mins);
}

$startTime = strtotime("2006-05-13 12:34:00");
$endTime = time();

print_r(getDiff($startTime, $endTime));
?>

my calculations may be a tad off, but the principle is there. what is really confusing me, though, is your statement that timestamps are easier... if you use DATETIME fields, mysql has built in calculations to allow you to find the differences between to times right within a query.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users