Solved

SQL - Select 180 days from today (Query)

Posted on 2013-01-03
3
2,283 Views
Last Modified: 2013-01-03
I used dateadd(d,-180,GETDATE())  which pulls wrong date.

SELECT  dateadd(d,-180,GETDATE())
--2012-07-07 14:36:21.380


select * from Table1
Where startdate>= 180 days from Today.

Roughly from June month onwards ??
0
Comment
Question by:chokka
[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
3 Comments
 
LVL 22

Accepted Solution

by:
Steve Wales earned 500 total points
ID: 38741562
The date shown is correct.

July through December is 6 months - roughly 180 days.

Today is January 3rd.  Allowing for 365 days in a year, 7th of July is about 180 days ago.

If you want from the start of June onwards, you're talking 210 days give or take (216 days if you want to be accurate and starting from today).
0
 

Author Comment

by:chokka
ID: 38741634
okay great, thanks !! just had a doubt on my query !!
0
 

Author Closing Comment

by:chokka
ID: 38741635
Thanks
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

752 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