Jump to content

Datediff syntax


graham23s

Recommended Posts

Hi Guys,

 

i'm trying to use the datediff in mysql to work out the days from when a member registered untill thye logged in! i have:

 

 
<?php
$q_date_diff = "SELECT DATEDIFF (`registered`,`last_login`) WHERE `id`='$users_id'";
$r_date_diff = mysql_query($q_date_diff);
$num_days = mysql_num_rows($r_date_diff);
print("Has been a member ($num_days) days.");
?>

 

but this throws up an error i take it my syntax is off is that right?

 

thanks guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/99222-datediff-syntax/
Share on other sites

mysql_num_rows() count the number of rows in the result set.

<?php
$q_date_diff = "SELECT DATEDIFF (`registered`,`last_login`) AS num_days WHERE `id`='$users_id'";
$r_date_diff = mysql_query($q_date_diff);
$rs = mysql_fetch_array($r_date_diff);
print("Has been a member ({$rs["num_days"]}) days.");
?>

Link to comment
https://forums.phpfreaks.com/topic/99222-datediff-syntax/#findComment-507710
Share on other sites

Hi Mate,

 

there seems to be an error with my query i even did this in a simple state to test:

 

<?php
// date diff how many days... //
$q_date_diff = "SELECT DATEDIFF (`2008-03-16 04:53:45`,`2008-04-02 11:01:08`) AS num_days WHERE `id`='$users_id'";
$r_date_diff = mysql_query($q_date_diff);
$a_date_diff = mysql_fetch_array($r_date_diff);
$days = $a_date_diff['num_days'];

print("$q_date_diff");
print("Has been a member ($days) days.");
?>

 

i still get:

 

mysql_fetch_array(): supplied argument is not a valid MySQL result resource in

 

is it the syntaxt i have do you think?

 

cheers

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/99222-datediff-syntax/#findComment-507768
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.