1

Given this simple table:

create table comments (
  id numeric not null,
  comment text, 
  created timestamp not null default now()
);

Using dbeaver directly on the db from my pc, and executing this statement

insert into comments (id, comment)
select 1111, 'test';

the "created" field of the new record is: 2017-02-24 16:17:21 and that's my correct time (CET).

When I run the very same statement from a php script (running on a linux-based webserver connected to the db), the result is 2017-02-24 15:17:21. The linux server time is ok (that is, CET).

What am I missing?

6
  • In your PHP ini file, check the selected timezone. EDIT: Actually not quite sure why this would matter Commented Feb 24, 2017 at 15:39
  • Sounds like you're missing about an hour Commented Feb 24, 2017 at 15:39
  • @pteronewone that was a good one :) Commented Feb 24, 2017 at 16:02
  • @Andy I already tried to set date_default_timezone_set('CET'); Commented Feb 24, 2017 at 16:03
  • Have you tried this? stackoverflow.com/questions/16609724/… Commented Feb 24, 2017 at 19:15

1 Answer 1

0

As per the answer at this link, change your table definition to

create table comments (
   id numeric not null,
   comment text, 
   created timestamp not null default (now() at time zone ('CET'))
);

which will use the current datetime using the desired time zone.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.