1

How can i change the timestamp to my own timezone in mysql?

Here is my PHP code below:

$sql = "CREATE TABLE `mytable` (
`id` int(6) unsigned not null auto_increment,
`firstname` varchar(30) not null,
`lastname` varchar(30) not null,
`email` varchar(50),
`reg_date` timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ";
Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116
Goldy
  • 21
  • 3

1 Answers1

0

For a single table and column, you could make a view, converting only the timestamp column from the server's timezone to your actual timezone when you select from the view instead of the table itself.

CREATE VIEW `v_mytable` AS
select id
      ,firstname
      ,lastname
      ,email
      ,CONVERT_TZ(regdate,'UCT','US/Pacific') as regdate
 from mytable;

If you don't have CONVERT_TZ installed it's outlined over here how to install it: MySQL CONVERT_TZ()

Community
  • 1
  • 1