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
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
$tomorrow = mktime(0,0,0,01,25,1998);
echo "Month is ".date("m", $tomorrow);
For more info look here: PHP Date() Function
You may want the getdate function:
$today = getdate();
echo $today["mon"];
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
$first2chars = substr($tomorrow, 0, 2);
picks the first 2 characters of the string $tomorrow
take care