Search code examples
javascriptphpget

How to use getFullYear, getMonth and getDate in PHP?


I know how to use getFullYear();, getMonth(); and getDate(); in JavaScript:

$year = ($hFdate.getFullYear());
$month = ($hFdate.getMonth());
$day = ($hFdate.getDate());

How can I use these functions in PHP?


Solution

  • assuming your $hFdate is a string of date

            $hFdate="2018-09-14";
            $year = date('Y',strtotime($hFdate));
            $month = date('m',strtotime($hFdate));
            $year = date('d',strtotime($hFdate));