Loop from date to date

Discussion in 'PHP' started by tirso, May 28, 2009.

  1. #1
    hi to all

    how to use from date to date for looping.

    my date format (YY/MM/DD)
    I have a date from 2009/01/05 to 2010/03/20

    I want to execute into my sql query are

    
    select * from mytable where date_created between 2009/01/05 and 2009/01/31 //for 2009/01 (january 2009) records
    PHP:
    then next loop:

    select * from mytable where date_created between 2009/02/01 and 2009/02/31 //for 2009/01 (february 2009) records
    PHP:
    until to satisfied "to date (2010/03/20)";

    any suggestion would greatly appreciated

    thanks in advance

    Tirso
     
    tirso, May 28, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Can you tell me what the data type of the date_created column is (datetime, date, timestamp, etc...)?
     
    jestep, May 28, 2009 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    Your format will not work. You will need to do the following:

    
    
    // create a new field as DATE format
    select ALL dates - current
    
    foreach currentdate, convert to DATE -using explode
    insert DATE back
    
    // when done all dates, remove the current date format
    
    PHP:
    When this is done, you should have dates that can be searched, timed, etc..

    Peace,
     
    Barti1987, May 29, 2009 IP
  4. tirso

    tirso Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hi,

    thanks you so much for your immediate replied. My datecreated format is datetime.


    thanks

    Tirso
     
    tirso, May 31, 2009 IP