If I already have a variable:

$mydate = "2004-01-19";

is there a PHP way to display "January" from this? Maybe some kind of mktime() thing that I can't find?

The MySQL getdate() is great for queries ...

$month = $mydate['month'];

... but I don't want to have to drop this into a db just to retrieve the right format. And that only works off of timestamp and not date.

If any one knows of a way to do this, I'd appreciate your help.

Thanks.

    I've never checked to see if the mktime() can do it... what I have done in the past is the following:

    Make an array with the months in it, but leave the first key blank, so...

    $months = array('', 'January', 'February', 'March', 'April');
    

    etc

    Then you can strip off the two characters for the month from your timestamp using substr() and write that as a new variable (let's say $the_month).

    Then just echo your date out and echo the month by doing:

    echo $months[$the_month];
    

    mktime() might be a little quicker in processing if it can in fact do it... but the above method has worked fine for me in the past.

      Thanks all. Both methods work.

      I saw the strtotime() page in the manual, but did not process it. I think I got hung up on it being timestamp. (which it doesn't have to be).

      Appreciate your time!

        Also [man]date[/man]. Dunno why there is both that and strftime...

          Write a Reply...