tags:

views:

57

answers:

4

Hi guys.. I have a date variable like 10-25-1998 and I only want to echo 10. Can anyone help me about it? Thanks...

$dateString=date("m-d-Y", mktime(0,0,0,10,25,1998));
echo date('m', $dateString); // not working here....will print out 01
+2  A: 
$tomorrow = mktime(0,0,0,01,25,1998);
echo "Month is ".date("m", $tomorrow);

For more info look here: PHP Date() Function

Leniel Macaferi
A: 

You may want the getdate function:

$today = getdate();
echo $today["mon"];
Chris65536
+4  A: 

strtotime will not recognize "m-d-Y" format, so the only way to get the month out of that string is to just parse it yourself, knowing that it's the first value in your string:

$dateString=date("m-d-Y", mktime(0,0,0,10,25,1998));
$t = explode('-',$dateString);
echo $t[0]; //month
echo $t[1]; //day
echo $t[2]; //year
Crayon Violent
A: 
$first2chars = substr($tomorrow, 0, 2);

picks the first 2 characters of the string $tomorrow

take care

kossibox