Solved

dateadd problem

Posted on 2006-10-31
3
772 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
[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
3 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17845130
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
ID: 17845214

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
ID: 17845276
that will work
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

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…
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 extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

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