getdate() function ???

Discussion in 'PHP' started by tsabar, Jan 20, 2006.

  1. #1
    hi, i can't get the hang of these date functions and when i can use them and when i can't.

    i'm pulling date variables out of my mysql database in the following format:
    2005-11-30 12:08:55

    trying to check if the month is equal to January (for instance):

    $tdate = getdate($row['mydate']);
    if ($tdate['month'] == "January") {
    // execute code
    }

    something is wrong i think with the following line:
    $tdate = getdate($row['mydate']);

    how do i convert the data i pull from the database (2005-11-30 12:08:55) into a php date variable that i can check parts of it? (month, day, year)

    thanx!
    o
     
    tsabar, Jan 20, 2006 IP
  2. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $t = strtotime ($row[mydate]);
    $DateArray = getdate($t);
    $Month = $DateArray[mon];
    $Day = $DateArray[mday];
    $Year = $DateArray[year];
    PHP:
    You will need to echo these values to the screen to see what sort of output it gives before you create your if statements.

    For example it may output Jan or January for the month.
     
    dave487, Jan 20, 2006 IP
  3. tsabar

    tsabar Member

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    that did it, thanx!!!
     
    tsabar, Jan 20, 2006 IP