31

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

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
clu3Less
  • 1,812
  • 3
  • 17
  • 20

6 Answers6

58

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

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
14

Try this

Check this How do i get the gmt time in php

date_default_timezone_set("UTC");
echo date("Y-m-d H:i:s", time()); 
Community
  • 1
  • 1
vijaykumar
  • 4,658
  • 6
  • 37
  • 54
4

You had selected the time format wrong

<?php 
date_default_timezone_set('GMT');

echo date("Y-m-d,h:m:s");
?>
Ivin Polo Sony
  • 355
  • 3
  • 17
2

Use below date function to get current time in MySQL format/(As requested on question also)

echo date("Y-m-d H:i:s", time());
Shiv Singh
  • 6,939
  • 3
  • 40
  • 50
0

You are repeating the y,m,d.

Instead of

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

You should use it like

gmdate('Y-m-d h:m:s \G\M\T', time());
Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
Tarun
  • 3,162
  • 3
  • 29
  • 45
0

gmdate() is doing exactly what you asked for.

Look at formats here: http://php.net/manual/en/function.gmdate.php

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
Kacer
  • 679
  • 3
  • 12