vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   subtarct one timestamp from another (https://vborg.vbsupport.ru/showthread.php?t=147084)

co0kz 05-12-2007 03:31 PM

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.

co0kz 05-16-2007 12:45 PM

Anyone with any idea how this could be achieved?

UK Jimbo 05-16-2007 01:14 PM

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)

nexialys 05-16-2007 01:19 PM

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);

UK Jimbo 05-16-2007 01:22 PM

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'

co0kz 05-16-2007 05:07 PM

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.


All times are GMT. The time now is 09:24 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00968 seconds
  • Memory Usage 1,713KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete