#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    3
    Rep Power
    0
    There seem to be alot of ways to perform date subtraction but one way that I do not see in the documentation or posts is this:

    I have a date in the future (TIMESTAMP1). I want to find out how many days,hours,minutes,seconds between NOW() and TIMESTAMP1.

    All of the functions I have seen deal with either the difference in seconds, or formating a new date from the calculation. I am trying to get "countdown" information I guess you could call it, that says "x days, y hours, z minutes until TIMESTAMP.

    If I have missed something obvious, my apologies, but any help would be greatly appreciated.

    Thanks,
    kp


  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    The best idea I could come up with is to convert to a unix timestamp to get a difference in seconds. You would have to convert to ddhhmmss format from that.

    select unix_timestamp(date_field)-unix_timestamp() as sec_diff from table;
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    3
    Rep Power
    0
    Okay, that is something that I had considered but what is the best way to do the conversion to d:m:h:s afterwards?
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    $days=intval($timediff/86400);
    $remain=$timediff%86400;
    $hours=intval($remain/3600);
    $remain=$remain%3600;
    $mins=intval($remain/60);
    $secs=$remain%60;

    print "$days:$hours:$mins:$secs";

Similar Threads

  1. difference between two dates
    By dor1979 in forum PHP Development
    Replies: 10
    Last Post: August 24th, 2006, 05:25 AM
  2. Odd problem with a hash and foreach loop
    By quantumechanix in forum Perl Programming
    Replies: 7
    Last Post: December 15th, 2003, 05:06 PM
  3. difference bt two dates
    By nsiraj in forum MySQL Help
    Replies: 1
    Last Post: September 17th, 2003, 07:58 AM

IMN logo majestic logo threadwatch logo seochat tools logo