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)
 Convert input date to date+23:59:59 (end of day)

Author  Topic 

duanecwilson
Constraint Violating Yak Guru

273 Posts

Posted - 2009-08-13 : 10:31:27
This works: select dateadd(second, -1, dateadd(day, 1, convert(datetime, '01/02/2009', 112 )))

This does not: select dateadd(second, -1, dateadd(day, 1, convert(datetime, '01/02/2009', 112 )))

I want someone to be able to use the second format. Any ideas?

Duane

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-08-13 : 10:34:47
Don't used closed datetime filter searches. Use Open-Ended, like this!

SELECT *
FROM Table1
WHERE Col1 >= '20090517' AND Col1 < '20090518'

to get ALL records dated for 17th of May 2009 in Col1 column.



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

rocknpop
Posting Yak Master

201 Posts

Posted - 2009-08-13 : 10:37:00
select dateadd(second, -1, dateadd(day, 1, convert(datetime, '20091201', 112 )))

--------------------
Rock n Roll with SQL
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-08-13 : 10:40:46
Rock'N'Pop, what to do with the records dated 20091201 23:59:59.500 ?



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

duanecwilson
Constraint Violating Yak Guru

273 Posts

Posted - 2009-08-13 : 10:45:37
I appreciate all the ideas here. I am learning.

Duane
Go to Top of Page

rocknpop
Posting Yak Master

201 Posts

Posted - 2009-08-13 : 10:45:48
Yes Peso, as you mentioned open-ended search is the best solution for such a problem.
I did not think logically. Thanks for that.


--------------------
Rock n Roll with SQL
Go to Top of Page
   

- Advertisement -