Solved

dateadd problem

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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
Via a live example, show how to shrink a transaction log file down to a reasonable size.

803 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