Faqts : Business : Programming : Shopping For You : PHP : Function Libraries : Date and Time

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

28 of 35 people (80%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How can I get the month number from the month name?

Aug 4th, 1999 07:42
Nathan Wallace, Rasmus Lerdorf


This function should do the job:

    function month_to_int($mon) {
      $months = array('Jan'=>1,'Feb'=>2,'Mar'=>3,
                      'Apr'=>4,'May'=>5,'Jun'=>6,
                      'Jul'=>7,'Aug'=>8,'Sep'=>9,
                      'Oct'=>10,'Nov'=>11,'Dec'=>12);
      return($months[$mon]);
    }

i.e. I pass "Dec" and it returns 12