将时间戳记插入数据库+ 7天 [英] Insert timestamp into a database + 7 days

查看:51
本文介绍了将时间戳记插入数据库+ 7天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在MySQL中创建一个表,该表的时间戳字段比now()提前7天.

I am trying to create a table in MySQL that has a timestamp field that is 7 days ahead of now() is there a way to do this?

这是我当前的代码

CREATE TABLE tbl_reg
(
    reg_id int(7) NOT NULL auto_increment KEY,
    user_id int(7) NOT NULL,
    registration_key char(50) NOT NULL,
    registration_expires timestamp default now()+7days,
    stamp_created timestamp default now()
);

有人可以帮忙吗,因为我无法在mysql网站上找到类似的东西,并且想知道是否有办法吗?

Can anyone help as i cant find anything like this on the mysql site and wondered if there was a way to do it?

推荐答案

MySQL中有许多日期/时间函数可以在这里解决问题.

There are a number of date/time functions in MySQL that will do the trick here.

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add

registration_expires=DATE_ADD(NOW(), INTERVAL 7 DAY)

但是,您不能将表达式设置为默认表达式-您需要在INSERT查询中进行设置.请注意,即使您的expr值> 1,单位值也不会使用复数.

You can't set an expression as a default, though - you'll need to do it in your INSERT queries. Notice that even if your expr value is > 1 there is no plural used for the unit value.

这篇关于将时间戳记插入数据库+ 7天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆