Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Time/Date Question

Author  Topic 

rcr69er
Constraint Violating Yak Guru

327 Posts

Posted - 2009-01-08 : 04:58:10
Hi Guys
I have the following WHERE clause in my statement:
WHERE r.dateentered BETWEEN @StartDate AND DATEADD(d,+1,@EndDate).

The thing I am trying to achieve is changing the DATEADD(d,+1,@EndDate) to show the @EndDate plus 23 hours and 59 seconds, instead of one day.

Is this possible to do?

Thanking you in advance

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-01-08 : 05:01:09
U can do this by adding seconds or minutes to the date @enddate



Jai Krishna
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2009-01-08 : 05:01:25
try this

select * from
table
WHERE r.dateentered BETWEEN @StartDate AND DATEADD(s,-1,@EndDate+1)
Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-01-08 : 05:03:55


WHERE r.dateentered BETWEEN @StartDate AND DATEADD(s,86399,@EndDate).

Jai Krishna
Go to Top of Page

rcr69er
Constraint Violating Yak Guru

327 Posts

Posted - 2009-01-08 : 05:05:52
Thanks Guys!!!
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-01-08 : 05:23:07

select * from
table1
WHERE r.dateentered BETWEEN @StartDate AND @EndDate + '23:59'


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

ashishashish
Constraint Violating Yak Guru

408 Posts

Posted - 2009-01-08 : 05:39:00
if u want to add 59 minutes in your query then u use peso sir suggestion like..

select * from
table1
WHERE r.dateentered BETWEEN @StartDate AND @EndDate + '23:59'

and if u want to add
23 hours and 59 SECONDS then u use as same but with a bit changes...

select * from
table1
WHERE r.dateentered BETWEEN @StartDate AND @EndDate + '23:00:59'


Thanks....
Go to Top of Page
   

- Advertisement -