3

I'm all of a sudden getting the following error on a site that I've done, which has been working fine so far:

A PHP Error was encountered

Severity: Warning

Message: mktime() [function.mktime]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Antarctica/Macquarie' for 'EST/10.0/no DST' instead

This is the code in question:

$stamp=mktime(0,0,0,$month,$day,$year);

What's the issue here? How can I quickly make these errors go away? I'm using mktime in that format in a lot of places and its throwing an error in each place.

Francois Deschenes
  • 24,816
  • 4
  • 64
  • 61
Ali
  • 261,656
  • 265
  • 575
  • 769

2 Answers2

7

As the error says, you either need to specify a timezone using date_default_timezone_set('Antarctica/Macquarie'); or ini_set('date.timezone', 'Antarctica/Macquarie'); in your code or define date.timezone in php.ini.

deceze
  • 510,633
  • 85
  • 743
  • 889
Francois Deschenes
  • 24,816
  • 4
  • 64
  • 61
  • Can you please provide the code that i'd need to use in the php.ini file? – Ali Jul 17 '11 at 22:43
  • 1
    I don't recommend this, especially if this is going to be in a production environment. But if this is just something you are doing for fun or something you could just suppress the warning like: `$stamp = @mktime(0,0,0,$month,$day,$year);` It's not a good thing to get in a habit of though.So you should probably just fix you php.ini – Paul Jul 17 '11 at 22:46
  • 2
    @PaulPRO - Timestamps are an important concept when dealing with dates, especially since timestamp are based on the Unix Epoch (which is GMT). One should **never** suppress the error messages unless absolutely necessary. – Francois Deschenes Jul 17 '11 at 22:47
  • 1
    @Click Upvote - Make sure to restart your web server if you change `php.ini` as the changes will only take effect when it's restarted. – Francois Deschenes Jul 17 '11 at 22:48
0

Can you confirm that $month, $day, and $year are INT - or even not NULL?

Also look into date_default_timezone_set()

AlienWebguy
  • 76,997
  • 17
  • 122
  • 145