xyn Posted October 20, 2006 Share Posted October 20, 2006 Hey,I am creating my clients ticket system, so they can submit ticketsand I wanted to have a duration, basicalyl stamps the time the usersent their ticket / post, and When someone replys to it, it will takethe current time and subtract by the stamp which should leave thein-between time...1. I thought about using Strtotime(); to realise it would be much tohard work, when timestamps are easier...2. If i was to use timestamps how would i go about it?ThxAsh Link to comment https://forums.phpfreaks.com/topic/24548-a-small-issue-with-timestamps/ Share on other sites More sharing options...
obsidian Posted October 20, 2006 Share Posted October 20, 2006 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]<?phpfunction 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 https://forums.phpfreaks.com/topic/24548-a-small-issue-with-timestamps/#findComment-111865 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.