tags:

views:

34

answers:

5

Hi, I'm using the function

$data=date_default_timezone_set("Y-m-d");

and I'm getting the date like 0000-00-00 in my table. Can any one help me ?

A: 

date_default_timezone_set sets the default timezone and takes time zone identifier(e.g. "EST" or "EST5EDT"). After time zone is set you can use date function to format datetime value.

date_default_timezone_set("GMT"); // timezone you want to use if you don't want the OS default timezone
$dt = date("Y-m-d");
a1ex07
A: 

date_default_timezone_set receives a timezone identifier, not a date formatter.

You probably want something like date("Y-m-d").

Artefacto
A: 

date-default-timezone-set is used for setting a deafult timezone (like "Europe/Moscow"), not for setting date format. You might need to use "date('Y-m-d');"

kgb
A: 

Do you realize that you are providing a date format, not time zone? Proper argument would be in example "Europe/Prague", what you probably want is date() function

cypher
A: 

date_default_timezone_set() is used to set the default timezone used by date and time functions.

Calling the function as $data=date_default_timezone_set("Y-m-d") is wrong for two reasons:

  • The return value of the function is TRUE when the passed parameter is a valid timezone identifier, and FALSE when it's not a valid identifier.
  • The identifier you are using is not valid; it should be something like 'America/New_York'.
kiamlaluno