CURRENT_TIMESTAMP() inserting zeroed

Asked

Viewed 392 times

1

I am inserting more than 9000 records via query, but CURRENT_TIMESTAMP() -3 is inserting several fields with 0000-00-00 00:00:00. Is there any way to avoid it?

INSERT INTO yourls.yourls_url (keyword, url, title, timestamp, ip, clicks) VALUES
('teste', 'meusite.com/teste.htm';, 'Testando o encurtador', CURRENT_TIMESTAMP() -3, '198.xx.xxx.xxx', ''); 
  • You can enter the Insert code?

  • INSERT INTO yourls.yourls_url (keyword, url, title, timestamp, ip, clicks) VALUES ('test', 'http://www.meusite.com/teste.htm', 'Testing the shortener', CURRENT_TIMESTAMP() -3, '198.xx.xxx.xxx', '');

1 answer

3


In INSERT it is necessary to highlight what this means -3 for you can be less 3 hours(Brasilia time) but mysql does not know if it is 3 hours, days, months, years etc use the function subdate to decrease 3 hours from the current date. current_timestamp is synonymous with now().

INSERT INTO yourls.yourls_url (keyword, url, title, timestamp, ip, clicks)
VALUES
('teste', 'meusite.com/teste.htm', 'Testando o encurtador', SUBDATE(now(), INTERVAL 3 hour), '198.xx.xxx.xxx', '');

Example - sqlfiddle, compare the result of the last two queries they give 3 seconds of difference or it is necessary to specify that are hours as done in the first query.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.