MySql: unchangeable timezone - php

my hosting provider is Godaddy My server location is in Europe and It is in the Amsterdam time zone. support team says :
"As this is a s\hared hosting platform you would be able to get the
time zone which is installed in parent server.you cannot change it" .
i want to show Australian timezone. php.ini is not provided. both mysql Timestamp and PHP function date() showing wrong time.

PHP:
http://php.net/manual/en/function.date-default-timezone-set.php
ini_set('date.timezone', 'Australia/Australian');
I'm not sure about: Australia/Australian
You can update it :)
MySQL:
https://dev.mysql.com/doc/refman/5.7/en/time-zone-support.html

Related

Change default timezone is not working in php

Am trying to get my current time from cpanel
am using this code
date_default_timezone_set('Asia/Kolkata');
$timestamp = date("H");
echo $timestamp;
It works fine in localhost but in cpanel it shows different time.
So I check cpanel which default time is set here
echo 'Time zone is: '.date('e');
echo 'Time zone is: '.date_default_timezone_get();
It shows the result UTC is the time zone, Now how to set my default time zone that is 'Asia/kolkata'
Anyone Please give me some idea, Thanks in Advance
My cpanel files
Try to set your timezone in php.ini and restart server.
https://www.inmotionhosting.com/support/website/php/setting-the-timezone-for-php-in-the-phpini-file
You need to set timezone for Apache(web server) or Mysql ?
do you have access to WHM?
do you have access to SSH of your server?
Which version of Apache / PHP / Mysql you are using?
if you are on shared hosting you can not do it from cPanel, thats why required above details.
Thanks

wrong current time - php time function

I have a problem with the time function in PHP.
It provides a different time.
For example, the current time in my PC is 10:00AM, it appears 5 hours late..
any thoughts?
Thanks in advance
The server system is configured with the wrong timezone for your location. Fix that with date_default_timezone_set.
can change the timezone in php ini file also
e.g.
[Date]
; Defines the default timezone used by the date functions
date.timezone = "America/Los_Angeles"

PHP: How to read the current date/time from the server, not from php.ini

Here is my problem:
echo date('Y-m-d H:i:s');
echo date('Y-m-d H:i:s', mktime());
echo exec('date');
The output is:
2012-03-21 08:45:51
2012-03-21 08:45:51
Wed Mar 21 10:45:51 EDT 2012
Server time is off 2 hours from the time returned by php date(); or any other php date/time function. It happens because server time set to EST and PHP.INI date.timezone="America/Denver"
I need to synchronize those two, by using date_default_timezone_set, but I don't know in advance what is the difference.
Is there any other way to get local server time besides calling exec?
UPD: I know that php.ini setting is wrong and that I can change it. The problem is that this script will work on nobody knows what kind of servers. I can't go to each and every one of them and correct the php.ini file. I also don't know in advance what timezone will be on those servers. I need a dynamic solution that will work everywhere.
you can change the ini date time zone and print the date
ini_set('date.timezone', 'America/Los_Angeles');
Change value of date.timezone from php.ini [Date] and restart your server.
You can get your date.timezone value form-
http://au.php.net/manual/en/timezones.php
For Bangladesh I set in my php.ini [Date]
date.timezone = Asia/Dhaka
You get your php.ini in C:\xampp\php address for XAMP server and Windows.
OR
some hosts give you possibility to edit php.ini
look for php config in cpanel
On *nix, you can use formatting parameters to date to get what you need:
date +%z — timezone (hhmm)
date +%:z — timezone (hh:mm)
date +%Z — timezone abbreviation (e.g. "EDT")
Making a system call (e.g. echo exec('date +%z');) will bypass any INI settings as per date_default_timezone_get. Note that this function issues an E_WARNING if it reads from the system time, and indeed from PHP 5.4 it doesn't even allow reading from it — specifically because it can't be relied upon.
To be consistent, regardless of the server settings you should use UTC within your application. For ease of use, GMT is close enough to UTC for most purposes, so you can use gmdate().

Handling timezones in PHP and MySQL?

I'm testing out making an entry system but the problem is, my host's timezone is different from where I live. It's 3am on my server while on my local computer, the time is 4pm. How do I automatically adjust code that I pull from the database to be displayed as a timezone similar to where I'm at?
You can set the default timezone using the function date_default_timezone_set(). It sets the default timezone used by all date/time functions in a script.
date_default_timezone_set('America/Los_Angeles');
Have a look at this page:
http://php.net/manual/en/function.date-default-timezone-set.php
You can find a list of timezones here
http://php.net/manual/en/timezones.php
Alternatively you could change the php.ini file if you have the permissions for it. You could change the option date.timezone to your timezone like this:
date.timezone = "US/Central"
For more information about date.timezone, go to this website:
http://kb.siteground.com/article/How_to_change_the_datetimezone_value_in_PHP.html

mysql time and php time not the same

When I use current_timestamp with MySQL, I get the correct time, but when I use
$mysqldate = date( 'Y-m-d H:i:s' );
I get the date with with an hour delay (eg, 4:42 PM is 5:42 PM).
I understood that both function use the server's local time - can someone explain the difference?
Thanks.
The global system time will be set via the /etc/localtime file, which will be either a symlink or a copy of a zone file from /usr/share/zoneinfo/ on most systems. Applications will use this as their default.
PHP can override this in a couple different ways:
date.timezone in php.ini
setting the TZ environment variable, e.g. putenv("TZ=US/Central");
date_default_timezone_set function (in PHP >= 5.1.0)
MySQL can override this by running the following query immediately after connecting:
SET time_zone = 'US/Central'
There are php locale settings, it takes it from php.ini, not from system time
Maybe your PHP server thinks it's in a different time zone or it uses different locale and daylight saving time rules.

Categories