OiO.lk Blog PHP Convert one date format into another in PHP
PHP

Convert one date format into another in PHP


A datetime is being passed via Webhook API which I have no control over.

I have a PHP Endpoint that takes in the datetime, so I want to convert it to just a date.

The datetime comes over in this format:

2024-10-17 20:35:53 UTC

I want to set the date in a mm/dd/yyyy format.

This is what I’m trying in PHP:

$mrc_date_c3 = $payload['fields']['mrc_date_c3'];  <-- datetime variable that needs to be updated
$mrc_date_c3_format = date("m/d/y", $mrc_date_c3); <-- is my attempt to set the date

The result looks like this:

01/01/70

It should be like this:

10/17/2024

What did I do wrong and how do I fix it?



You need to sign in to view this answers

Exit mobile version