Solved

dateadd problem

Posted on 2006-10-31
3
774 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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

739 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