[SOLVED] convert a month into integer

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

[SOLVED] convert a month into integer

Post by gurjit »

Hi all,

how do i convert lets say 'Jan', 'Dec', 'Sep' into a integer value '1','12','9'?

The month is in the database as a 3 letter character.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

simple swith statement

Code: Select all

switch($month)
{
  case "jan":
    $mon = 1;
    break;
  case "feb":
    $mon = 2;
    break;

// etc.....
}
echo $mon;
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

Code: Select all

SELECT DATE_FORMAT('Jan','%d');
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

Post by gurjit »

thanks worked great
Post Reply