The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
subtarct one timestamp from another
looking for a way to subtract one timestamp value from another and output the result as..
ie.. $remainingtime = $timestamp1 - $timestamp2 and then output $remainingtime as the below result resulting in.. 2 Days 10 Hours 33 Minutes 14 seconds. (example) i know and understand how the timestamp value works but i can't figure out how i would split seconds into the above example. I've searched both here and vb.com and done a wider search and can't seem to find how this could be done without altering core files whicvh i don't really want to do if i can help it. Ideas on how this is acheivable would be greatly appreciated. |
#2
|
|||
|
|||
Anyone with any idea how this could be achieved?
|
#3
|
||||
|
||||
once you've subtracted them you have the difference in seconds and just have to do simple maths on it.
$seconds = $remainingtime % 60; // remainder when divided by 60 $minutes = floor($remainingtime / 60); // 60 seconds in a minute $hours = floor($remainingtime / 3600); // 60 * 60 (secs in an hour) $days = floor($remainingtime / 86400); // 60 * 60 * 24 (secs in a day) |
#4
|
|||
|
|||
actually it depend on what timestamp you want to evaluate ?!... posts or birthdays have different structures...
if it is posts, simple: X-Y=Z >> real time = vbdate(Z, true); |
#5
|
||||
|
||||
If they're UNIX timestamps then the method I described would work.
If they're not then you could query any MySQL DATE/DATETIME field from the database using FROM_UNIXTIME(colname) to cast it into a UNIX timestamp. eg SELECT id, name, FROM_UNIXTIMESTAMP(date_col) FROM table WHERE this='that' |
#6
|
|||
|
|||
hi there thanks for your help with this. After a little messing about with the code you provided (yes im dealing with unix timestamps) i managed to figure out where i was going wrong with this.
Thanks for you time and help. Much appreciated. |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|