I have a Stored Procedure having input parameter as @startDate as datetime and I am using this parameter to compare this fields to table column. I want to convert that @startDate field if the timestamp is not passed by the user in SP?

Example: Let's say if user passes @startDate = '01/14/2018 6:30:00 PM' then no it is should be taken as it is in the SP but if @startDate is passed as '01/14/2018' only then it should be converted to '01/14/2018 11:59:59 PM'.

1 Answer 1


There's a few ways. Here's one.

declare @startDate datetime = '20180114'

if @startDate = cast(@startDate as date)
    set @startDate = dateadd(second,-1,dateadd(day,1,@startdate))

select @startDate

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.