Display timestamp details

[expired user #10406]'s profile image [expired user #10406] posted 7 years ago in General Permalink

Is there a means to display either time zone offset or time zone abbreviation for timestamp fields in the data view?

kalvaro's profile image kalvaro posted 7 years ago Permalink

What exact database server and data type are you referring to?

[expired user #10406]'s profile image [expired user #10406] posted 7 years ago Permalink

Database server is mysql 5.0.95. Heidisql version is 9.4.0.5125. Data type is TIMESTAMP. I read (somewhere), that the TIMESTAMP data type stores offsets while the DATETIME does not, but I can't figure out how to display such in Heidisql. Thanks to Ben Franklin's bad joke, a quarter-millennium ago, we get to deal with daylight savings time in our enlightened age. Functions associated with TIMESTAMP look like the best way to address this.

kalvaro's profile image kalvaro posted 7 years ago Permalink

It's not actually that way. From official docs:

MySQL converts TIMESTAMP values from the current time zone to UTC for storage, and back from UTC to the current time zone for retrieval. (This does not occur for other types such as DATETIME.) By default, the current time zone for each connection is the server's time. The time zone can be set on a per-connection basis. As long as the time zone setting remains constant, you get back the same value you store. If you store a TIMESTAMP value, and then change the time zone and retrieve the value, the retrieved value is different from the value you stored. This occurs because the same time zone was not used for conversion in both directions. The current time zone is available as the value of the time_zone system variable.

In other words, column time zone is hard-coded as UTC and cannot be changed so there's really no need to display it.

In HeidiSQL though you have a couple of time zone related features: an advanced option in session manager to use client's time zone (rather than server's) and a status bar pane that I honestly cannot remember what exactly shows (but appears to be UTC for reference).

[expired user #10406]'s profile image [expired user #10406] posted 7 years ago Permalink

At this point, I'm trying to verify what data is stored in the database. My machine and the server are both in America/Los_Angeles time zone, so I don't know that the advanced session manager option is of any help. Some of my data is America/New_York. The timezone table is not loaded in mysql, but several blurbs I've read suggest it's not necessary when a php script handles the queries. I ran an insert query that included the statement if($company == 'HOS_CIN' or $company == 'HOS_FER') { date_default_timezone_set("America/New_York"); } Then I ran two scripts on sample data - one with and one without the same statement. The first script returned a time of noon EST and the second script returned a time of noon PST. If mysql had retained the UTC offset, shouldn't I have seen a three-hour difference in the times?

Please login to leave a reply, or register at first.