Jump to content

A small issue with Timestamps


xyn

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
Link to comment
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.
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.