Date / Time Conversion (PHP)

Is there an easy way to convert date and time, for example:

Sun, 14 Mar 2010 09:00:00 GMT

In this format:

20100306T153626

in php

+3
source share
2 answers

Use strtotimeand datefunctions.

$result = date('Ymd\THis', strtotime('Sun, 14 Mar 2010 09:00:00 GMT'));

A β€œT” must be escaped because it has a special meaning (short for time zone).

+5
source

You need a date function . Format string for 20100306T153626:

YmdTHis

i.e.

date("Ymd\THis");

for current date / time. If you want to use your time, you will need this as a Unix timestamp in which you can use the mktime function to do this.

+1
source

Source: https://habr.com/ru/post/1736197/


All Articles