Can you use date() ??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Can you use date() ??

Post by simonmlewis »

Is there anything wrong in using this:

Code: Select all

$todaydate = date('Y-m-d');
I am getting a vast amount of errors saying:
[Wed Jun 19 07:16:40 2013] [warn] [client 90.209.131.62] mod_fcgid: stderr: PHP Warning: 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 'Europe/London' for 'BST/1.0/DST' instead in /var/www/vhosts/site.co.uk/httpdocs/includes/categ.inc
Is it as simple as putting this at the top of the template file?

Code: Select all

date_default_timezone_set('GMT');
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: Can you use date() ??

Post by pbs »

you can set date timezone in php.ini file
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Can you use date() ??

Post by simonmlewis »

date.timezone = Europe/London
Do I just add this line of code?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: Can you use date() ??

Post by pbs »

yeah, you can set time zone according to your requirement, please check this url

http://php.net/manual/en/timezones.php
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Can you use date() ??

Post by simonmlewis »

Cool - added it as described to PHP.ini. Will see tomorrow if the (over 1million) lines of errors have reduced by this. As a shed of them were down to times.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Can you use date() ??

Post by pickle »

It might be best to set the timezone to UTC, then translate to Europe/London time (which I think is GMT anyway). This will allow your code to work regardless of where the server is located, and will simplify any timezone translation you may need to do for users that aren't in the GMT timezone.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply