Welcome Guest, Not a member yet? Register   Sign In
problem with "date" helper
#1

[eluser]SomeFunkyDude[/eluser]
I'm trying to get a timestamp into the database and keep getting an error.

As a test I ran the code below by itself

Code:
$datestring = "Year: %Y Month: %m Day: %d - %h:%i %a";
$time = time();
echo mdate($datestring, $time);

but I get this... (the time shows but the error message pops up)
Code:
A PHP Error was encountered

Severity: Warning

Message: date() [function.date]: 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 'America/New_York' for '-4.0/DST' instead

Filename: helpers/date_helper.php

Line Number: 94

Year: 2009 Month: 10 Day: 04 - 04:30 pm
#2

[eluser]jedd[/eluser]
Do you still get this error after you fixed up your php.ini file (ie. adding a date.timezone entry)?
#3

[eluser]SomeFunkyDude[/eluser]
Thanks,

I didn't see where to change the default timezone in the php.ini

but I did find a php function called date_default_timezone_set() so I called this with the parameter being "America/New_York". Now I need to find a spot to autoload it I suppose or throw it in the date helper's constructor.

Only thing is displaying the time to users in different time zones.
#4

[eluser]jedd[/eluser]
[quote author="SomeFunkyDude" date="1254712871"]
I didn't see where to change the default timezone in the php.ini
[/quote]

The [Date] section.
#5

[eluser]SomeFunkyDude[/eluser]
that's what I thought, I tried changing it but was still getting the error.
#6

[eluser]jedd[/eluser]
Check apache logs for insight. It's unlikely you misspelt it, or that you have > 1 [Date] section.

Assuming you remembered to restart apache after making this change ... ?
#7

[eluser]John_Betong[/eluser]
[quote author="SomeFunkyDude" date="1254713933"]that's what I thought, I tried changing it but was still getting the error.[/quote]
 
 
Please note that this is not an error, it is a warning.
 
Here is the setting which works on my computer, I have the code in the first couple of lines of my index.php AFTER declaring the error_reporting level.
Code:
// correct place to prevent warnings from showing
error_reporting(E_ALL | E_NOTICE | E_STRICT);
ini_set('display_errors', 'On');

//set yoour timezone
date_default_timezone_set('Asia/Krasnoyarsk'); // Bangkok time

// incorrect place to call error_reporting(...)
error_reporting(E_ALL | E_NOTICE | E_STRICT);
 
Either reduce your error_reporting(...) to not show warnings or ensure date_default_timezone_set(...) is called after error_level(...).
 
 
 
edit: logic error, changed before to after




Theme © iAndrew 2016 - Forum software by © MyBB