Please help with SQL query
im storing the timestamp in mysql database in (INT) column, And i want to search the rows with between the dates. Anyone would please help what should be the Sql query to find the rows between two dates?
dates are entered like
Code:
FROM = 21-08-2011
TO = 01-09-2011
getting time stamp with the following code
PHP Code:
$time = time();
what wud be the Sql query :-| to get proper rows
Re: Please help with SQL query
.. it really seems like you keep asking the same question over and over. there are many MySQL date and time functions which do exactly what you want them to. but, the MySQL date format is YYYY-MM-DD, so you should change the format you're using or parse what you have to get the format MySQL wants.
Code:
WHERE `date` BETWEEN UNIX_TIMESTAMP('2011-08-21 00:00:00') AND UNIX_TIMESTAMP('2011-09-01 23:59:59')
if you notice the times given to both of these, the search will be inclusive of 8/21/2011 and 9/01/2011. If you want the records that happened literally between these, you'll need to adjust the times accordingly.
Re: Please help with SQL query
I personally would have stored the dates as datetime fields rather than int but you could also use the php mktime() function.
PHP Code:
$query .= "WHERE `date` BETWEEN ". mktime(0,0,0,8,21,2011) ." AND ". mktime(0,0,0,9,1,2011) ." ";