Results 1 to 3 of 3

Thread: Please help with SQL query

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    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

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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.
    Like Archer? Check out some Sterling Archer quotes.

  3. #3
    Member PBertie's Avatar
    Join Date
    Aug 2011
    Location
    Newcastle Upon Tyne
    Posts
    55

    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
  •  



Click Here to Expand Forum to Full Width