Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

dateadd problem

Posted on 2006-10-31
3
Medium Priority
?
784 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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 shrink a transaction log file down to a reasonable size.
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…

704 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