You get βJanuary 1970β as the output because you tried to create a date from the timestamp 197402 , which is in seconds since January 1, 1970. If you output the complete line from it (with seconds and whatnot), you will see that it is a valid timestamp giving the actual date, but they all end in early January 1970, see this online demo .
This format, YYYYMM, is not a recognizable format for most functions. You need to split it if you know that the format will be that way - and use this data instead. You can use substr() to split the string, and then convert the numeric month to the string associated with that month using date() and mktime() (since you just specify the year and month).
Next snippet
$arr = [197402, 192201, 184707]; foreach ($arr as $v) { $year = substr($v, 0, 4); $month = substr($v, 4, 2); echo date("FY", mktime(0, 0, 0, $month, 0, $year))."<br />";
displays
February 1974
January 1922
July 1847
Alternatively, you can use the DateTime class (which is much easier to work with) and create from a given format using date_create_from_format()
foreach ($arr as $v) { echo date_create_from_format('Yh', $v)->format('F Y')."<br />"; }
This will generate the same output as above.
References
Qirel source share