Search code examples
phpdatetimetimestampunix-timestamp

Data from Timestamp


I try to show the right day to some specific timestamps but I get for different days every time to 31st day and for the last 3 timestamps 30th day.

$old_date = date("Y-m-t", $timestamp);

Left you can see the output and right the timestamp:

2017-10-31 - 1507326468,
2017-10-31 - 1507409268,
2017-10-31 - 1507492068,
2017-10-31 - 1507574869,
2017-10-31 - 1507657669,
2017-10-31 - 1507740469,
2017-10-31 - 1507823270,
2017-10-31 - 1507906070,
2017-10-31 - 1507988870,
2017-10-31 - 1508071671,
2017-10-31 - 1508154471,
2017-10-31 - 1508237271,
2017-10-31 - 1508320072,
2017-10-31 - 1508402872,
2017-10-31 - 1508485672,
2017-10-31 - 1508568472,
2017-10-31 - 1508651273,
2017-10-31 - 1508734073,
2017-10-31 - 1508816873,
2017-10-31 - 1508899674,
2017-10-31 - 1508982474,
2017-10-31 - 1509065274,
2017-10-31 - 1509148075,
2017-10-31 - 1509230875,
2017-10-31 - 1509313675,
2017-10-31 - 1509396476,
2017-10-31 - 1509479276,
2017-11-30 - 1509562076,
2017-11-30 - 1509644876,
2017-11-30 - 1509727676


Edit: I have to write:

$old_date = date("Y-m-d", $timestamp);

Stupid mistake.


Solution

  • t you use in the date("Y-m-t", $timestamp); stands for 'Number of days in the given month'. See the manual. You probably want to use j, which stands for 'Day of the month without leading zeros'.