SQL 如何计算 1 个月 currentDate 之后的日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10226236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to calculate a date after 1 month currentDate
提问by CPM
How can I calculate a date after a month of current date.
如何计算当前日期一个月后的日期。
Example if I have 19/04/2012 I want to get 19/05/2012. Is there any function on sql that allows doing this?
例如,如果我有 19/04/2012,我想得到 19/05/2012。sql 上是否有任何功能允许这样做?
I need to do the same for a year also like 19/04/2012 and set 19/04/2013
我需要做同样的一年也像 19/04/2012 并设置 19/04/2013
Cheers
干杯
回答by Mithir
回答by Darren
To add 1 month to the current date:
要将 1 个月添加到当前日期:
SELECT DATEADD(m, 1, GETDATE())
To add 1 year to the current date:
要将 1 年添加到当前日期:
SELECT DATEADD(YY, 1, GETDATE())
For additional arguments see:
有关其他参数,请参阅:
回答by Alejandro B.
You can use DateAdd:
您可以使用日期添加:
select dateadd(m, 1, getdate())
select dateadd(yy, 1, getdate())
search online for other period indicators such as hour, minute, etc!
在线搜索其他周期指标,例如小时、分钟等!
回答by sihol
Something like this should do the job
像这样的事情应该可以胜任
SELECT DATEADD(month, 1, '2012-04-19')
SELECT DATEADD(月, 1, '2012-04-19')
for a year
一年
SELECT DATEADD(year, 1, '2012-04-19')
SELECT DATEADD(年, 1, '2012-04-19')
回答by hitman047
You can use this query for 1 month ahead date . This query works fine in oracle.
您可以提前 1 个月使用此查询。此查询在 oracle 中工作正常。
select add_months(trunc(sysdate),1) from dual;
For 1 year ahead date use this query
对于提前 1 年的日期,请使用此查询
select add_months(trunc(sysdate),12) from dual;