Well, 5.3 likes region/city format and calls sensible gmt deprecated. In ancient times we not only got to do our own arithmetic, we had to do it. Now we have to know geography instead -- not degrees at 15 of those per hour, but placenames unrelated to the reasons for degrees and all of that. Progress; not.
Short answers are, no, and if.
The practical answer on timezones in php is not always short.
Confusion can arise where you are in one location, your host is in another (based primarily in, say, London or Redmond or Houston or Santa Rosa), and your machine is in yet another (respectively Illinois or California or Utah or Texas). That seems to have fostered some of the confusion well above where offsets were not making complete sense to people relative to host, zero longitude (gmt, utc), and hometown.
____________________________________________________
(1) Your host might allow you access to a reasonably full php.ini for your account, perhaps in basic and advanced views. (The server's own master php.ini is on the order of 2,000 lines long, you will not be allowed to touch those.) In such a php.ini are these "timezone" entries (for the nn.mmm formats see further down):
;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;
; Defines the default timezone used by the date functions
;date.timezone =
;date.default_latitude = nn.mmmm
;date.default_longitude = nn.mmmm
;date.sunrise_zenith = nn.mmmm
;date.sunset_zenith = nn.mmmm
date.timezone = "UTC"
You can likewise also uncomment (remove ;) these two so as to have:
date.default_latitude = [use the nn.mmmm format explained below] ; precede with a ";" any notes to yourself
date.default_longitude = [use the nn.mmmm format explained below] ; precede with a ";" any notes to yourself
You can use phpinfo.php to see what you've accomplished that you may need to edit.
____________________________________________________
(2) One group of specifics, with examples:
http://www.php.net/manual/en/function.date-date-set.php
date_date_set — Alias of DateTime::setDate
http://www.php.net/manual/en/function.d ... ne-get.php
date_default_timezone_get — Gets the default timezone used by all date/time functions in a script
http://www.php.net/manual/en/function.d ... ne-set.php
date_default_timezone_set — Sets the default timezone used by all date/time functions in a script
____________________________________________________
(3) Another group of specifics:
Supported Date and Time Formats
Time Formats
Date Formats
Compound Formats
Relative Formats
in detail at:
http://www.php.net/manual/en/datetime.formats.time.php
http://www.php.net/manual/en/datetime.formats.date.php
http://www.php.net/manual/en/datetime.f ... mpound.php
http://www.php.net/manual/en/datetime.f ... lative.php
____________________________________________________
(4) More than you ever wanted to know about time a la php is outlined here:
http://www.php.net/manual/en/book.datetime.php
at . . .
date_time_set — Alias of DateTime::setTime
date_timestamp_get — Alias of DateTime::getTimestamp
date_timestamp_set — Alias of DateTime::setTimestamp
date_timezone_get — Alias of DateTime::getTimezone
date_timezone_set — Alias of DateTime::setTimezone
date — Format a local time/date
getdate — Get date/time information
gettimeofday — Get current time
gmdate — Format a GMT/UTC date/time
gmmktime — Get Unix timestamp for a GMT date
gmstrftime — Format a GMT/UTC time/date according to locale settings
idate — Format a local time/date as integer
localtime — Get the local time
microtime — Return current Unix timestamp with microseconds
mktime — Get Unix timestamp for a date
strftime — Format a local time/date according to locale settings
strptime — Parse a time/date generated with strftime
strtotime — Parse about any English textual datetime description into a Unix timestamp
time — Return current Unix timestamp
timezone_abbreviations_list — Alias of DateTimeZone::listAbbreviations
timezone_identifiers_list — Alias of DateTimeZone::listIdentifiers
timezone_location_get — Alias of DateTimeZone::getLocation
timezone_name_from_abbr — Returns the timezone name from abbreviation
timezone_name_get — Alias of DateTimeZone::getName
timezone_offset_get — Alias of DateTimeZone::getOffset
timezone_open — Alias of DateTimeZone::__construct
timezone_transitions_get — Alias of DateTimeZone::getTransitions
timezone_version_get — Gets the version of the timezonedb
The practical answer on timezones in php is not always short.
Confusion can arise where you are in one location, your host is in another (based primarily in, say, London or Redmond or Houston or Santa Rosa), and your machine is in yet another (respectively Illinois or California or Utah or Texas). That seems to have fostered some of the confusion well above where offsets were not making complete sense to people relative to host, zero longitude (gmt, utc), and hometown.
____________________________________________________
(1) Your host might allow you access to a reasonably full php.ini for your account, perhaps in basic and advanced views. (The server's own master php.ini is on the order of 2,000 lines long, you will not be allowed to touch those.) In such a php.ini are these "timezone" entries (for the nn.mmm formats see further down):
;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;
; Defines the default timezone used by the date functions
;date.timezone =
;date.default_latitude = nn.mmmm
;date.default_longitude = nn.mmmm
;date.sunrise_zenith = nn.mmmm
;date.sunset_zenith = nn.mmmm
date.timezone = "UTC"
You can likewise also uncomment (remove ;) these two so as to have:
date.default_latitude = [use the nn.mmmm format explained below] ; precede with a ";" any notes to yourself
date.default_longitude = [use the nn.mmmm format explained below] ; precede with a ";" any notes to yourself
You can use phpinfo.php to see what you've accomplished that you may need to edit.
____________________________________________________
(2) One group of specifics, with examples:
http://www.php.net/manual/en/function.date-date-set.php
date_date_set — Alias of DateTime::setDate
http://www.php.net/manual/en/function.d ... ne-get.php
date_default_timezone_get — Gets the default timezone used by all date/time functions in a script
http://www.php.net/manual/en/function.d ... ne-set.php
date_default_timezone_set — Sets the default timezone used by all date/time functions in a script
____________________________________________________
(3) Another group of specifics:
Supported Date and Time Formats
Time Formats
Date Formats
Compound Formats
Relative Formats
in detail at:
http://www.php.net/manual/en/datetime.formats.time.php
http://www.php.net/manual/en/datetime.formats.date.php
http://www.php.net/manual/en/datetime.f ... mpound.php
http://www.php.net/manual/en/datetime.f ... lative.php
____________________________________________________
(4) More than you ever wanted to know about time a la php is outlined here:
http://www.php.net/manual/en/book.datetime.php
at . . .
date_time_set — Alias of DateTime::setTime
date_timestamp_get — Alias of DateTime::getTimestamp
date_timestamp_set — Alias of DateTime::setTimestamp
date_timezone_get — Alias of DateTime::getTimezone
date_timezone_set — Alias of DateTime::setTimezone
date — Format a local time/date
getdate — Get date/time information
gettimeofday — Get current time
gmdate — Format a GMT/UTC date/time
gmmktime — Get Unix timestamp for a GMT date
gmstrftime — Format a GMT/UTC time/date according to locale settings
idate — Format a local time/date as integer
localtime — Get the local time
microtime — Return current Unix timestamp with microseconds
mktime — Get Unix timestamp for a date
strftime — Format a local time/date according to locale settings
strptime — Parse a time/date generated with strftime
strtotime — Parse about any English textual datetime description into a Unix timestamp
time — Return current Unix timestamp
timezone_abbreviations_list — Alias of DateTimeZone::listAbbreviations
timezone_identifiers_list — Alias of DateTimeZone::listIdentifiers
timezone_location_get — Alias of DateTimeZone::getLocation
timezone_name_from_abbr — Returns the timezone name from abbreviation
timezone_name_get — Alias of DateTimeZone::getName
timezone_offset_get — Alias of DateTimeZone::getOffset
timezone_open — Alias of DateTimeZone::__construct
timezone_transitions_get — Alias of DateTimeZone::getTransitions
timezone_version_get — Gets the version of the timezonedb
Yes Sir, This can be very confusing for a non developer user, My advice is to go with a module.
Opencart Extension store has a few which can solve this issue of Local Time for the store.
Regards
Opencart Extension store has a few which can solve this issue of Local Time for the store.
Regards
Bean Bags Online Shopping | Bean Bags | Bean Bags Refill
Bean Bag Shop Online India | Bean Bag Chairs Online
Free and fee both. Whether you ask local time or time zone or all three, extensions for that do not all appear on the first page or two. Pay attention to version compatibilities, and test, that is not a good thing to have go haywire.
You can use this extension to solve your purpose. Its very easy to install and use. Try this:
http://www.opencart.com/index.php?route ... n_id=15772
http://www.opencart.com/index.php?route ... n_id=15772
After following instructions in this thread ... it's showing + 30 minutes ... how I can adjust that?
@PlusCybernet
I saw your post dated May 9, 2014 reading as under:
I saw your post dated May 9, 2014 reading as under:
I am having exact same problem. Did you get around this? If so kindly share. Thanks & regards.After following instructions in this thread ... it's showing + 30 minutes ... how I can adjust that?
Thanks for the posted information, keithb. You have helped me solve my problem. However, all I needed to do was change this line, mysql_query("SET TIME_ZONE = '0'");, to include my offset hour from GMT 0:00. I am 5 hours behind GMT so my offset hour is -5. If you know you offset hour, simply go to /system/database/mysql.php and edit mysql_query("SET TIME_ZONE = '-5:00'");. You will find it after the line mysql_query("SET SQL_MODE = ''", $this->link);
Before:
After:
That's it.
Before:
Code: Select all
mysql_query("SET SQL_MODE = ''", $this->link);
mysql_query("SET TIME_ZONE = '0:00'");
Code: Select all
mysql_query("SET SQL_MODE = ''", $this->link);
mysql_query("SET TIME_ZONE = '-5:00'");
The above is not present in oc ver2.0.3.1 so how to change the time zone in that case, I have tried php.ini, index.php, .htaccess though the time zone has changed on the server(checked using phpinfo.php) but the orders placed do not reflect the actual or real time of my zone(GMT +5.30). Any help would be greatly appreciated.streetpreacher wrote:Thanks for the posted information, keithb. You have helped me solve my problem. However, all I needed to do was change this line, mysql_query("SET TIME_ZONE = '0'");, to include my offset hour from GMT 0:00. I am 5 hours behind GMT so my offset hour is -5. If you know you offset hour, simply go to /system/database/mysql.php and edit mysql_query("SET TIME_ZONE = '-5:00'");. You will find it after the line mysql_query("SET SQL_MODE = ''", $this->link);
Before:After:Code: Select all
mysql_query("SET SQL_MODE = ''", $this->link); mysql_query("SET TIME_ZONE = '0:00'");
That's it.Code: Select all
mysql_query("SET SQL_MODE = ''", $this->link); mysql_query("SET TIME_ZONE = '-5:00'");
Thank you for your time
Regards,
Sun Systems
Industrial Electronics and Instrumentation
Hi, how can this thing work in version 2.1 ?keithb wrote:Sometimes in OpenCart the effect of different timezones can affect what is stored in the database and displayed to the user.
Whilst the defaults work correctly on my local pc I found that on a Live server they did not and Dates/Times for Orders and Order History were not being displayed as I would like
The issue is that typically the Web server running PHP can be set to a different timezone to the database server and one cannot always get sufficient access to change the settings permanently, especially if on shared servers.
I have seen several posts here about partial solutions for this and the best I could find was the free module storetime by Fido-X http://forum.opencart.com/viewtopic.php?f=119&t=30188 but even this does not currently address the issue when the database needs changing and not just the web server/php. So even this did not fully sort my problem.
I live in the UK but my hosting is in the America/Chicago TimeZone and I wanted my reports / cut-off times etc to be in my local UK time
So at say 15:33 UK time (allowing +1 hour as we are on BST (British Summer Time) at the moment)
I would expect a UTC/GMT timezone to show/display as 14:33
However Chicago is -5 hours from UCT it showed as 9:33am
i.e. a total of -6 hours different which was very confusing/misleading with Order Histories
Now there are various approaches to using timezones and whether one should store everthing in UTC and then convert just for display purposes in the local timezone or whether to store all values as from the local timezone.
If the dates were stored in datestamp columns (which are simply Integers with on offset in seconds from a Unix start date) then any local dates would get put into the database as UTC and converted back automatically to local dates as they were retrieved. This makes for easy datetime arithmetic but has the overhead of changing these values.
However I did not want to change the database schema from the currently used datetime fields for this in case there were any side-effects elsewhere in the code (datetime columns just store what they are passed and often the servers use UTC as a standard).
As I found nearly 200 instances of the mysql function NOW() used in the modules I decided I wanted to store the datetime fields as actual local UK time but I didn't want to alter every occurrence of NOW() in the code.
I also wanted to allow for any British Summer Time changes.
I couldn't set the database using TimeZone names as not all servers have this configured correctly so I needed to use the offset for it to always work.
So overall I decided to take the approach of
1. Setting the webserver/php timezone to the one I wanted (Europe/London in my case)
2. Calculate what Offset this TimeZone had from UTC/GMT
3. Use this Offset to set the Database to this TimeZone Offset
This is the way I did it though the code may well get improved by others!
There are timezone settings within PHP which are currently set in system/startup.php around line 50
This only sets a value using date_default_timezone_set if there is NO current setting so I changed it to always set my required TimeZone
RemoveReplace with (or the required timezone)Code: Select all
if (!ini_get('date.timezone')) { date_default_timezone_set('UTC'); }
I also have QPhoria's excellent VQMod and I found there was a similar line thereCode: Select all
date_default_timezone_set('Europe/London');
In vqmod\vqmod.php
Find and deleteThe main code logic went into system/database/mysql.php so is only called once per page.Code: Select all
date_default_timezone_set('UTC');
(I fdidn't use any configs as they are set much later in the process after the initial database connection)
AfterAddCode: Select all
mysql_query("SET SQL_MODE = ''", $this->connection);
This solved my problem but it depends on your hosting as to whether you need or want to use it or not.Code: Select all
// get local time on Web/PHP server $localtime = strtotime(date('Y-m-d H:i:s')); //get local time in GMT/UTC (i.e GMT/UTC is set as +0:00 on database and other timezones are set as +/- hours of this) $gm_localtime = strtotime(gmdate('Y-m-d H:i:s')); //find offset in hours (if any - which allows for Daylight Saving Time or British Summer Time (BST)) $diff_hours = ($localtime - $gm_localtime) / 3600; //Then the Database server needs to be set to this Offset to store/retrieve values as local ones $adjust = "SET time_zone = '"; if ($diff_hours > 0) { $adjust .= "+" . ceil($diff_hours); } elseif ($diff_hours < 0) { $adjust .= floor($diff_hours); } else { $adjust .= "+0"; } $adjust .= ":00'"; mysql_query($adjust, $this->connection);
There is a free module on opencart market place to do this and it's super easy!
https://www.opencart.com/index.php?rout ... r_rating=2
https://www.opencart.com/index.php?rout ... r_rating=2
Who is online
Users browsing this forum: Ahrefs [Bot] and 151 guests