I want to parse the date 1938
1938+02:00
using date()
& strtotime()
.
My code:
echo date("Y", strtotime("1938+02:00"));
gives me as result "2014"..
What am i doing wrong?
I want to parse the date 1938
1938+02:00
using date()
& strtotime()
.
My code:
echo date("Y", strtotime("1938+02:00"));
gives me as result "2014"..
What am i doing wrong?
For something like this just get the first four characters of the string. No need to work with dates and such:
echo substr('1938+02:00', 0, 4);
But if you insist on using date functionality you'll need to use DateTime::createFromFormat()
as that date string is not a standard format.
$date = DateTime::createFromFormat('YP', '1938+02:00');
echo $date->format('Y');
date("Y");
only return the year. That's what the Y
does.
See the Manual page for date for other options.
EDIT
Another thing to consider, is that timestamps only go back to 1970. That's what a timestamp is (the number of seconds since 1970).
So, that's going to give you a negative value for the timestamp.
Your date string is not in an acceptable format. here is a list of acceptable formats for strtotime