I have a date in this format 2068-06-15
. I want to get the year from the date, using php functions. Could someone please suggest how this could be done.
$date = DateTime::createFromFormat("Y-m-d", "2068-06-15"); echo $date->format("Y");
@scoota269 is right - and you can test this using echo date("Y-m-d", $oldDateUnix) . In this case, it even bugs up and results (1970-01-01) which is unix time 0.
You can use the date function. I'm using strtotime to get the timestamp to that day ; there are other solutions, like mktime , for instance.
The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.
$date = DateTime::createFromFormat("Y-m-d", "2068-06-15"); echo $date->format("Y");
The DateTime class does not use an unix timestamp internally, so it han handle dates before 1970 or after 2038.
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