...

View Full Version : Get day/month/year from date string?



john6
10-22-2012, 10:14 AM
Please help! How can I get the date elements from a string?

This is what I've got so far, but it's not working.


$strDate = "6/25/2012";
$newDate = date("j/n/Y",$strDate);

echo "day is " . $newDate['mday'] . "<BR/>";
echo "month is " . $newDate['mon'] . "<BR/>";
echo "year is " . $newDate['year'] . "<BR/>";

Thanks in advance,
John.

bjarneo
10-22-2012, 10:49 AM
Try this-ish



$strDate = "6/25/2012";

$t = strtotime($strDate);
$getDate = getdate($t);

printf('day is %d <br /> month is %d <br /> year is %d', $getDate['mday'], $getDate['mon'], $getDate['year'] );



Edit: You can use $getDate[] as you wish. Doesn't have to be in printf function.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum