Microsoft SQL -- getdate(YYYY-MM-DD) ?

Below works.

How can I change the below 2013-08-26 15:30:00.000 to something like
getdate(YYYY-MM-DD) 15:30:00.000 since I always want it to
displays today at 3:30pm ?
---------------------------------------------------------------------------
UPDATE TIME_SCANNING
SET Status = 'STOP',
    TotalTime =
        CASE
        WHEN (DATEPART(HOUR, DateTime) < 11) OR
             (DATEPART(HOUR, DateTime) = 11 AND DATEPART(MINUTE, DateTime) < 15)
         THEN (cast(cast(datediff(minute, DateTime , '2013-08-26 15:30:00.000' )as decimal(30,4)) / 60 as decimal(30,2)) - .5)/ Qty
         ELSE
         cast(cast(datediff(minute, DateTime , '2013-08-26 15:30:00.000' )as decimal(30,4)) / 60 as decimal(30,2)) / Qty
        END
finance_teacherAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
This gives you YYYY-MM-DD
SELECT CONVERT(char(10), '2013-08-26 15:30:00.000',126)

btw not real sure what your question is here..
0
DcpKingCommented:
check out these examples: it should get you on your way:
select cast(getdate() as date)
select cast(cast(getdate() as date) as datetime)
select dateadd(minute, 3810, cast(cast(getdate() as date) as datetime))

Open in new window


hth

Mike
0
ralmadaCommented:
try this way:

dateadd(d, 0, datediff(d, 0, yourcolumn)) + '15:30:00'

example:

declare @t datetime
set @t = '2013-08-26 11:30:00.000' 
select dateadd(d, 0, datediff(d, 0, @t)) + '15:30:00'

Open in new window

0
finance_teacherAuthor Commented:
How can I change the below #1 to something like
"getdate(),126)' 15:30:00.000" since I always
want today @ 3:30pm ?

UPDATE TIME_SCANNING
SET Status = 'STOP',
    TotalTime =
        CASE
        WHEN (DATEPART(HOUR, DateTime) < 11) OR
             (DATEPART(HOUR, DateTime) = 11 AND DATEPART(MINUTE, DateTime) < 15)
              --#1 below works and is what I want --> making "TotalTime=6.15" which is correct, but I want 2013-08-26 to be today's date
              --THEN (cast(cast(datediff(minute, DateTime , '2013-08-26 15:30:00.000' )as decimal(30,4)) / 60 as decimal(30,2)) - .5)/ Qty
             
              --#2 below works but is not what I want --> making "TotalTime=14.65" since it goes to end-of-today instead of just 3:30pm today
              THEN (cast(cast(datediff(minute, DateTime , CONVERT(char(10), getdate(),126))as decimal(30,4)) / 60 as decimal(30,2)) - .5)/ Qty

        END
0
ralmadaCommented:
use this:

dateadd(d, 0, datediff(d, 0, getdate())) + '15:30:00'

so in your case:

--THEN (cast(cast(datediff(minute, DateTime , dateadd(d, 0, datediff(d, 0, getdate())) + '15:30:00' )as decimal(30,4)) / 60 as decimal(30,2)) - .5)/ Qty
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.