0

A wanna format timestamps into a date format like so: 'Y-m-d H:i:s' => 'yyyy-mm-dd hh:ii:ss'.

I tried to formatting with date function:

date('Y-m-d H:i:s', $comments[0]['created'])

and with DateTimeImmutable class:

$date = new DateTimeImmutable();
$acctualDate = $date->setTimestamp($comments[0]['created']);
$fomatedDate = $acctualDate->format('Y-m-d H:i:s');

but both give the same result.

I have this four date:

int(1679909217390)
int(1677169312318)
int(1676548411827)
int(1674216062741)

So i tried format with 'Y-m-d H:i:s', but the result is not right:

string(20) "55204-03-15 17:16:30"
string(20) "55117-05-19 20:31:58"
string(20) "55097-09-14 12:10:27"
string(20) "55023-10-18 17:25:41"

Then i tried format with this 'y-m-d H:i:s', but the result is still not right:

string(17) "04-03-15 17:16:30"
string(17) "17-05-19 20:31:58"
string(17) "97-09-14 12:10:27"
string(17) "23-10-18 17:25:41"

The datetime is almost correct, but the year is definitly not. I have not found solution for my problem.

So my question is how get datetime with the correct year, that fits in this format 'yyyy-mm-dd hh:ii:ss'?

Thank you very much for your spending time, and your help.

Chabi_Browny
  • 29
  • 1
  • 10
  • 1
    Please always show the literal code you are using when asking questions here. You will save a lot of time, miscommunication and irritation. Even (or especially) with simple questions like these. Thank for the next time! – Roemer Apr 02 '23 at 02:58
  • 1
    @Roemer - Thank for the reply. I edited the question. Hopefully it's okay now. Thank you for your help, and time. – Chabi_Browny Apr 02 '23 at 10:41
  • 1
    I saw you already had an answer, thanks for your time and patience to edit the question anyway, this may help people in the future with similar problems! – Roemer Apr 02 '23 at 12:40

0 Answers0