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
 General SQL Server Forums
 New to SQL Server Programming
 append time to date

Author  Topic 

msugradus
Starting Member

40 Posts

Posted - 2007-06-12 : 13:45:25
I have a user enter a start end end date to create a report and I would like to append a static time 23:59:59 to the date that the user enters. I have tried several methods and I am having no luck.....

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-06-12 : 13:46:48
Instead of using BETWEEN and trying to add 23:59:59 to the second date, you are better off doing this:

where SomeDate >= @startDate and SomeData < @endDate



- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

subrata4allfriends
Starting Member

24 Posts

Posted - 2007-06-12 : 14:51:21
Hi,
Please try those examples,

EXAMPLE 1:
SELECT CONVERT(VARCHAR(10), GETDATE(),120) + ' 23:59:59'

EXAMPLE 2:
SELECT CONVERT(VARCHAR(10), '2007-06-01 00:42:40.000',120) + ' 23:59:59'

EXAMPLE 3:
SELECT CONVERT(VARCHAR(10), YOUR_COLUMN_NAME,120) + ' 23:59:59'
FROM YOUR_TABLE_NAME

"Life is not a bed of roses."
Go to Top of Page

yumyum113
Starting Member

31 Posts

Posted - 2007-06-12 : 20:29:51
May be this would help.

declare @startdate datetime
declare @enddate datetime

set @startdate = '01/01/2007 12:00'
set @enddate = getdate()

select dateadd(s,-1,datediff(d,0,@startdate)+1) as 'Start date',dateadd(s,-1,datediff(d,0,@enddate)+1) as 'End date'


/*
Variables @startdate and @enddate are the date entered by the user
*/
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-12 : 23:25:55
see199,

Your question is not directly related to this thread. Please start a new thread for your question.


KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-13 : 08:40:41

http://www.sql-server-performance.com/fk_datetime.asp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -