I have a relativly simple problem, but I am not very strong in php, so I'm having some diffculties getting this to work.
I have a DB that holds a membership registration date and I need to compare that against the current date to tell them how many days they have left on thier membership. But, I can't get it work.
Here is some of what I have.
$memdate = mysql_result($memberdate, "membershipdate"); //pulls date from DB
$d1 = getdate($memdate);
$d2 = date("Y-m-d");
$_SESSION['memberdate'] = $d2['yday']-$d1['yday']; //amount of days between DB date & now
I know thats obviously not right, but could someone tell me what I'm doing wrong? The field in the MySQL db is setup as DATE if that helps. Does it read and compare these as strings?
Ok, well let me include a little more info, because it works, but it's not returning the correct amount of days.
the SQL call is as follows:
$memberdate = mysql_query("SELECT membershipdate FROM users WHERE username='$username' AND password='$password'");
The particular user that I'm using established his membership on 2006-08-24
But when the code runs, it returns -123 for the days left on his membership.
I might be wrong here, but to me, it almost seems like thats taking the total number of days in the year and subtracting it minus how many days were into the year already.