$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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With