Forum Moderators: coopster
I have:
$date = $row['date']; //result from above query ex. 122300433
Now I want to perform that into another query:
Ex.
$query = mysql_query("Select id, date FROM table WHERE date='$date'");
The example show where is the same date and time exatly.
The problem is, how I can do this where is not the same time but same day,moth,year.
ceil($date / (24 * 60 * 60))
(you're dividing the number of seconds since 1970 by 60[seconds per minute] x 60[minutes per hour] x 24[hours per day], get it?)
So if you put that into your mysql query, you would need:
WHERE CEIL(date / (24 * 60 * 60)) = CEIL($date / (24 * 60 * 60))
Should work, that is if you're using Unix time stamp (although the example you provided is some time in 1973, so I don't know if that's what you're using)
But first I convert date in day format:
$date = date('d m Y', $date); //13 04 2009
Now need to convert date field, but how?
$query = mysql_query("Select id, date, date_FORMAT('date', '%d %m %Y') AS newdate FROM table WHERE newdate='$date'");
This show mysql error "Error Number: 1054 Error: Unknown column 'newdate' in 'where clause' "
newdate not exist as field but I rename "date" field runnig "date_FORMAT('date', '%d %m %Y') AS newdate".
Chances are that you can't do much about the table field name in this case, but at least change the variable name. Use something like:
$checkdate = date('d m Y', $date);
Then the WHERE clause would be something like:
WHERE checkdate=date_FORMAT('date', '%d %m %Y') AND id='2'
(Note- I am not a PHP programmer, so you may need to tweak it a bit.)