Solved

t-sql add days to getdate function

Posted on 2014-12-11
2
302 Views
Last Modified: 2014-12-11
When I run this:

-- end of todays date
SELECT DATEADD(DAY, DATEDIFF(DAY, '19000101', GETDATE()), '23:59:59')

I get this:

2014-12-11 23:59:59.000

How do I add 5 days to this.
I want 5 days added to GETDATE()  in the same format .

So I want to get this:

2014-12-16 23:59:59.000
0
Comment
Question by:maqskywalker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 250 total points
ID: 40495384
Since the code already uses DATEADD, just add five to the middle parameter (increment)

SELECT DATEADD(DAY, DATEDIFF(DAY, '19000101', GETDATE()) + 5, '23:59:59')
0
 
LVL 49

Assisted Solution

by:PortletPaul
PortletPaul earned 250 total points
ID: 40495392
DO NOT USE '23:59:59' because that is NOT the end of the day.

It is one second short of the end of the day.

The end of today's day is ( 00:00:00 of tomorrow )
e.g.
if today is 16th December 2014, then the end of that day is '2014-12-17 00:00:00'

to set time to 00:00:00 from getdate() use
dateadd(day, datediff(day,0, getdate() ), 0)
or
cast(getdate() as date)

then to add 5 days use dateadd(day,5, .... ) where ... is one of the options above

also note to avoid use of between for date/time ranges.
see: "Beware of Between"
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question