Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add days to the current date?

I am trying to add days to the current date and it's working fine but when I add 360 days to the current date it gives me wrong value.

eg: Current Date is 11/04/2014

And I am adding 360 Days to it, it should give me 11/04/2015, but it is showing the same date 11/04/2014. the year is not changing.

Here is my code:

select dateadd(dd,360,getdate()) 
like image 438
Fazil Mir Avatar asked Apr 11 '14 12:04

Fazil Mir


People also ask

How do I add 7 days to a date in Excel?

Add or subtract days from a date Enter your due dates in column A. Enter the number of days to add or subtract in column B. You can enter a negative number to subtract days from your start date, and a positive number to add to your date. In cell C2, enter =A2+B2, and copy down as needed.

How do I add 30 days to a date in Excel?

In cell C1, type =A1+30, and then press RETURN . This formula adds 30 days to the date in cell A1.


2 Answers

Just do-

Select (Getdate()+360) As MyDate 

There is no need to use dateadd function for adding or subtracting days from a given date. For adding years, months, hours you need the dateadd function.

like image 54
Shahid Mustafa Avatar answered Sep 30 '22 16:09

Shahid Mustafa


select dateadd(dd,360,getdate()) will give you correct date as shown below:

2017-09-30 15:40:37.260

I just ran the query and checked:
Please check the attached image

like image 44
Mahantesh Avatar answered Sep 30 '22 16:09

Mahantesh