1

I am trying to convert a given date and time in format ( yyyy-mm-dd hh:mm:ss ) to (yyyymmddThhmmssZ) in php. For example: 2020-07-30 18:30:00 should be 20200730T183000Z. I also want to know if there are any existing/in-built methods to accomplish this?

1 Answers1

0

As others have said in your comments, you can simply do this with the DateTime object

Here's an example:

$date = '2020-07-21 18:50:32';
$obj = new \DateTime('@' . strtotime($date));
echo $obj->format(DATE_RFC3339); // 2020-07-22T01:50:32+00:00

If RFC3339 isn't your preferred format, feel free to pick one from the manual, or build your own

Try it out: http://sandbox.onlinephpfunctions.com/code/3246477b676e17022da799697acf4df375e1fe08

zanderwar
  • 3,440
  • 3
  • 28
  • 46