Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2011

    Unanswered: Calculating date difference

    Firstly, I should state I am a major newb. I'm trying to calculate the difference between two dates in a table. The table has two fields 'qdate', and 'currdate' set up as timestamps. All I'm trying to do is figure out the difference between the two dates in the fields.
    I've tried timestampdiff with no luck. So now I'm trying it this way but I get the result 0. Am I missing something simple here?

    PHP Code:
    $result mysql_query("SELECT *
    FROM time"
    $row mysql_fetch_array$result );

    $currdate $row[currdate];
    $qdate $row[qdate];

    echo (
    $currdate $qdate

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    what did you try?
    what difference are you looking for?
    ..days, hours, months....
    MySQL :: MySQL 5.5 Reference Manual :: 11.7 Date and Time Functions
    gives you lots of options.. I'd expect timediff would of more use to you

    alternatively you could do the date calcualtions in PHP
    PHP: Date/Time Functions - Manual
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Oct 2011
    Thanks for the link healdem I worked it out from your php link

    I ended up making the field type an integer, inserting unix timestamps and then running this:

    $result = mysql_query("SELECT * FROM time");
    $row= mysql_fetch_array( $result );

    $a = (time() - $row['qdate']);
    $b = '600';
    if ($a > $b) {
    echo updated;
    Thanks for taking a look

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts