$date ='20101015';
how to convert to $year = 2010
,$month = 10
, $day =15
thanks
$date ='20101015';
how to convert to $year = 2010
,$month = 10
, $day =15
thanks
You can use the PHP substring function substr
as:
$year = substr($date,0,4); # extract 4 char starting at position 0.
$month = substr($date,4,2); # extract 2 char starting at position 4.
$day = substr($date,6); # extract all char starting at position 6 till end.
If your original string as leading or trailing spaces this would fail, so its better feed substr
trimmed input as. So before you call substr
you can do:
$date = trim($date);
You can use substring function
http://www.w3schools.com/php/func_string_substr.asp
$year=substr($date,0,4);
$month=substr($date,4,2);
$day=substr($date,6,2);