Reputation: 1864
If I run the following query:
ALTER TABLE `price_s` ADD COLUMN `ts` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER `price_s_id` ;
The new column would be populated with 0000-00-00 00:00:00
.
Value in this column won't get updated to Current Timestamp until I modify the column, i.e. ON UPDATE CURRENT_TIMESTAMP
seems to work fine.
If I run :
SELECT version( ) , @@time_zone , @@system_time_zone , NOW( ) , UTC_TIMESTAMP( )
I got:
'5.5.15', '+10:00', 'EST', '2012-08-23 14:56:59', '2012-08-23 04:56:59'
I'd like to store the UTC time in the column ts
, how do I do that?
Not sure if this is relevant, I have tried to generate the mysql.time_zone*
tables:
Miranda-Macbook: ./mysql_tzinfo_to_sql /usr/share/zoneinfo | ./mysql -p -u root mysql
Enter password: Warning: Unable to load '/usr/share/zoneinfo/+VERSION' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Asia/Riyadh87' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Asia/Riyadh88' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Asia/Riyadh89' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Mideast/Riyadh87' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Mideast/Riyadh88' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Mideast/Riyadh89' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Thanks @Sameer and @Marc B. Now I understands timestamp more.(with the help of this article) It is already stored in UTC, so what I need is actually:
SET time_zone = 'SYSTEM';
UPDATE tablename SET ts=now()
Upvotes: 1
Views: 2088
Reputation: 360782
INSERT INTO yourtable (ts) VALUES (now())
UPDATE yourtable SET ts=now()
As long as whatever you're stuffing into the ts field is a valid mysql timestamp string (yyyy-mm-dd hh:mm:ss
) it doesn't matter WHAT the timezone is. That only becomes relevant upon conversion or retrieval - mysql datefields themselves have no concept of timezones, they're just repositories of some date/time data.
Upvotes: 2