datetime formate issue–help | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

datetime formate issue–help

Hi
i’m not good at SQL programming. but i need to re-format a variable like this: @current_date=getdate() it’s "2007-04-08 15:41:54.447" now. but i wish the @current_date can be cut to "2007-04-08 15:00:00"
—–something like re-formate @current_date could anyone tell me if i can do that?
thanks in advance, xuka
Try this query to convert time to the format you want, hope that helps<br /><br /><br />SELECT CONVERT (VARCHAR(10), GETDATE(),111)+’ ‘+ CONVERT(VARCHAR(3),GETDATE(),10<img src=’/community/emoticons/emotion-11.gif’ alt=’8)’ />+’00:00′
DECLARE @current_date DATETIME<br />[email protected]_date = CONVERT (VARCHAR(10), GETDATE(),111)+’ ‘+ CONVERT(VARCHAR(3),GETDATE(),10<img src=’/community/emoticons/emotion-11.gif’ alt=’8)’ />+’00:00′<br />[email protected]_date<br /><br />Should have posted this before the first one… <img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ />

DECLARE @current_date DATETIME
SELECT @current_date = CONVERT (VARCHAR(30), dateadd(hour, datediff(hour, 0, GETDATE()), 0), 121)
SELECT @current_date
Please do the formating in the front end.
KH
thank you all for your reply. they are really helpful to me. have a good day
]]>