I have an array of Date values in the format of 'Y-m-d'. I want to loop over the array and only extract the day ('d') of each member, but can't figure out to split it. Do I use substrings in some way?
Put simply, I have '2010-11-24', and I want to get just '24' from that. The problem being the day could be either single or double figures.
If you just want the day as a string, you can use format(as. Date(df$x,format="%Y-%m-%d"), "%d") .
If you have PHP < 5.3, use strtotime():
$string = "2010-11-24"; $timestamp = strtotime($string); echo date("d", $timestamp); If you have PHP >= 5.3, use a DateTime based solution using createFromFormat - DateTime is the future and can deal with dates beyond 1900 and 2038:
$string = "2010-11-24"; $date = DateTime::createFromFormat("Y-m-d", $string); echo $date->format("d");
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