Jump to content

Archived

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

xyn

A small issue with Timestamps

Recommended Posts

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

Share this post


Link to post
Share on other sites
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:
[code]
<?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));
?>
[/code]

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.

Share this post


Link to post
Share on other sites

×

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.