Page 1 of 1
Converting 3 char month into numerical equavalent
Posted: Fri Nov 28, 2003 7:50 am
by RedRasper
Hi all,
Wonder if someone could help me. I'm sure there must be a way to do this using the date/time etc functions, but i can't see how!
I have a 3 digit month (ie 'Nov') and want to turn it into its numberical version (ie 10).
Could anyone help me?
Many thanks
RedRasper
Posted: Fri Nov 28, 2003 8:01 am
by Nay
I'm not used to looking around so I normally make my own scripts out of my own Ideas till someone like m3rjak point me PHP's built in functions <_< lol. Anyhow, you can have an array of the months and use array_search() to find the key of the month.
-Nay
Posted: Fri Nov 28, 2003 8:01 am
by Cruzado_Mainfrm
make an array with all the elements in order
then search the array for a match
ex:
Code: Select all
<?php
$months = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
$theday = 'Mar';
$numberday = array_search($theday, $months) +1;
echo $numberday;
?>
Posted: Fri Nov 28, 2003 8:10 am
by RedRasper
Thank you both!
Nice little idea, I has thought about something like that, but dismissed it as i thought i'd have to do a for loop to search the array! Didn't know about array search!
Cheers!
RedRasper
Posted: Fri Nov 28, 2003 8:16 am
by patrikG
[php_man]strtotime[/php_man] is your friend. If you couple it with [php_man]date[/php_man] you'll be sorted.
Posted: Fri Nov 28, 2003 11:01 am
by RedRasper
Hi patrikG
Thank you for that wonderful function I never knew existed! Thats two for me today!
Its a bit annoying though as I have written quite a few routines myself to work out weeks etc! Ah well you live and learn!
Thank you again,
RedRasper
Posted: Sat Nov 29, 2003 4:25 am
by patrikG
Glad it helped.