echo $current_year = date("Y").'<br><br>';
echo $string_year = strftime("%Y", strtotime($current_year));
I want to change date(Year)
to string but this code show output as 1970
.
I don't understand why it is 1970
?
How to make current year that is 2016
. please help.
The entire date should be passed within strtotime(), and not just the year. Or you could simply pass the timestamp as the second parameter.
Try this:
echo $string_year = strftime("%Y", time());
OR
echo $string_year = strftime("%Y", strtotime("now"));
Your issue is that the strftime
function takes a timestamp
as the second param but you are passing a string.
=> string strftime ( string $format [, int $timestamp = time() ] )
Thus when you pass date("Y").'<br>'
technically this is not a timestamp
anymore and this defaults to the 1st year that our php works from being 1970.
When doing
echo $current_year = date("Y");
echo $string_year = strftime("%Y", strtotime($current_year));
I get 2016
but honestly I don't understand why you are asking for the year then changing it to a year again since both $current_year
and $string_year
are strings.
echo $current_year = date("Y");
echo $string_year = strftime("%Y", strtotime($current_year));
echo gettype( $current_year); //Output: string
echo gettype( $string_year); //Output: string