-
Oct 1st, 2011, 10:26 PM
#1
Thread Starter
Fanatic Member
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
-
Oct 2nd, 2011, 09:35 AM
#2
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.
-
Oct 5th, 2011, 05:20 AM
#3
Member
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) ." ";
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|