Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert date/time (PHP) [duplicate]

Tags:

php

Is there an easy way to convert date and time like this:

Sun, 14 Mar 2010 09:00:00 GMT

To this format:

20100306T153626

in PHP

like image 361
CLiown Avatar asked Jan 24 '26 04:01

CLiown


2 Answers

Use the strtotime and date functions.

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

The “T” has to be escaped, because it has special meaning (timezone abbreviation).

like image 76
Matěj G. Avatar answered Jan 25 '26 18:01

Matěj G.


You want the date function. The format string for 20100306T153626 is:

YmdTHis

i.e.

date("Ymd\THis");

for the current date/time. If you want to use your own time, you'll need it as a Unix timestamp, which you can use the mktime function for that.

like image 37
Andy Shellam Avatar answered Jan 25 '26 17:01

Andy Shellam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!