Solved

dateadd problem

Posted on 2006-10-31
3
758 Views
Last Modified: 2012-05-05
I have a problem with dateadd I'm using it like this:
dattimin BETWEEN (DATEADD(day, -14, GETDATE())) AND (DATEADD(day, -7, GETDATE()))
the results have the dates right  but I need the first part to look for Date:00:00:00.00 and the last Date:23:59:59.00
so I can return all records within that datetime range all records have a time value in them
0
Comment
Question by:portly
3 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
declare @d datatime
set @d = convert(datetime, convert(varchar(10), getdate(), 120), 120)

select ....
dattimin BETWEEN (DATEADD(day, -14, @d)) AND (DATEADD(day, -7, @d))
0
 
LVL 11

Accepted Solution

by:
rw3admin earned 500 total points
Comment Utility

Declare @GetDate DateTime

Select @Date=Convert(Varchar(10),Getdate(),101)

Select * from your table where dattimin BETWEEN(DATEADD(day, -14, @GetDate)) and
DATEADD(day, -7, DateAdd(ms,86399000,@GetDate))

if you acutally want last date to have 23:59:59.997 time then use
Select * from your table where dattimin BETWEEN(DATEADD(day, -14, @GetDate)) and
DATEADD(day, -7, DateAdd(ms,86399997,@GetDate))
0
 

Author Comment

by:portly
Comment Utility
that will work
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MIcrosoft SQL, query with ANY joins 13 28
MS SQL 2014 get SPIDs of users 6 25
t-sql complement 8 29
Sort by Month and Year - SQL 3 21
In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now