Date Mathematics
Posted: Mon Jun 12, 2006 8:26 pm
I have been trying over the last 24hrs to figure out how to do simple mathematics with dates. I am getting desperate. All of the examples I have reviewed seem so simple, but I am just not getting it. Basically, I have used the Now() function to record a timestamp in my MySQL database when someone signs in and set the number of downloads to 0. I then want to record their downloads. This is working fine, but once they sign in again, it sets the counter all over again because the date formula is getting a Null value (or at least that is what I think is happening). I want to limit the amount of downloads a user can perform each day.
Here is what I have done so far
Any help would be appreciated.
Here is what I have done so far
Code: Select all
$first_date = getdate( );
$second_date=getdate($row[1]); //$row[1] is returned in the mysql query, it is the timestamp using Now() and the field is in timestamp format
$days_between = $second_date['yday'] - $first_date['yday'];
if ($days_between==0) {
echo "";//do nothing
}else{
echo "Reset the download counter";// if this is a different day reset the download counter
}Any help would be appreciated.