PHP Parse Date String

后端 未结 8 1523
春和景丽
春和景丽 2021-01-11 18:14

If I\'ve got a date string:

$date = \"08/20/2009\";

And I want to separate each part of the date:

$m = \"08\";
$d = \"20\";         


        
8条回答
  •  忘掉有多难
    2021-01-11 19:06

    Dominic's answer is good, but IF the date is ALWAYS in the same format you could use this:

    $m = substr($date,0,2);
    $d = substr($date,3,2);
    $y = substr($date,-4);
    

    and not have to use an array or explode

    Bill H

提交回复
热议问题