How to get GMT date in yyyy-mm-dd hh:mm:ss in PHP

clu3Less picture clu3Less · Nov 23, 2013 · Viewed 105k times · Source

I want to get the current date in yyyy-mm-dd hh:mm:ss format.

I have tried:

gmdate('yyyy-mm-dd hh:mm:ss \G\M\T', time());

Its returning a wierd date:

13131313-1111-2323 0707:1111:3131

Answer

Hanky Panky picture Hanky Panky · Nov 23, 2013

You don't have to repeat those format identifiers . For yyyy you just need to have Y, etc.

gmdate('Y-m-d h:i:s \G\M\T', time());

In fact you don't even need to give it a default time if you want current time

gmdate('Y-m-d h:i:s \G\M\T');  // This is fine for your purpose

Manual

You can get that list of identifiers Here