Roy Harper
Coder
I have blog page in my website. Whenever I write a blog, I only save the content of the blog, and let the SQL handle the current timestamp.
So my code goes like this:
[CODE lang="sql" title="SQL code"]CREATE TABLE blogs(
blogID INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
img VARCHAR(128),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);[/CODE]
However, when I changed the time in my computer 1 day ahead, the CURRENT_TIMESTAMP also saves 1 day ahead.
This made me think what would be the best way to get the current datetime that does not affect saving even if I change computer's datetime.
should I save the date in PHP code or is there something else to do or code in SQL to achieve this?
So my code goes like this:
[CODE lang="sql" title="SQL code"]CREATE TABLE blogs(
blogID INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
img VARCHAR(128),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);[/CODE]
However, when I changed the time in my computer 1 day ahead, the CURRENT_TIMESTAMP also saves 1 day ahead.
This made me think what would be the best way to get the current datetime that does not affect saving even if I change computer's datetime.
should I save the date in PHP code or is there something else to do or code in SQL to achieve this?