If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Calculating date difference

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-12-11, 04:33
lhadley91 lhadley91 is offline
Registered User
 
Join Date: Oct 2011
Posts: 2
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
Reply With Quote
  #2 (permalink)  
Old 10-12-11, 04:57
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
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 my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 10-12-11, 16:02
lhadley91 lhadley91 is offline
Registered User
 
Join Date: Oct 2011
Posts: 2
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:

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

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On