Receiving a request the day after tomorrow

I want to select the date the day after tomorrow in sql. For example, I want to make a query that picks a date after two days. If I selected today's date from the calendar (29-04-2015) then it should show the date in another textbox as (01-05-2015). I want a query that is retrieved the day after tomorrow. So far I have completed the request below:

SELECT VALUE_DATE FROM DLG_DEAL WHERE VALUE_DATE = GETDATE()+2

      

early

+3


source to share


4 answers


Note that if you have a date field containing time information, you need to truncate the date part with DATEADD

dateadd(d, 0, datediff(d, 0, VALUE_DATE))

      

To compare 2 dates, ignoring the date part, you can simply use DATEDIFF



SELECT VALUE_DATE FROM DLG_DEAL
WHERE datediff(d, VALUE_DATE, getdate()) = -2

      

or

SELECT VALUE_DATE FROM DLG_DEAL
WHERE datediff(d, getdate(), VALUE_DATE) = 2

      

+4


source


Try it like this:

SELECT VALUE_DATE 
FROM DLG_DEAL WHERE VALUE_DATE = convert(varchar(11),(Getdate()+2),105)

      



SQL FIDDLE DEMO

+3


source


SELECT VALUE_DATE FROM DLG_DEAL WHERE datediff(d, VALUE_DATE, getdate()) = -2

      

+1


source


** I think you should try this **

       SELECT DATEADD(day,2,VALUE_DATE) AS DayAfterTomorrow
       FROM DLG_DEAL WHERE VALUE_DATE= GETDATE();

      

DATEADD (choiceToAdd, interval, date)

This function allows you to add or judge the day, month, year, etc. from the date of. This interval is nothing more than a numeric value that you want to add or subtract.

+1


source







All Articles