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
 need date as yyyymmdd format with date

Author  Topic 

archana23
Yak Posting Veteran

89 Posts

Posted - 2014-10-30 : 11:56:18
hi

I am using below query to get the data and time+2 hrs

select dateadd(hour, datediff(hour, 0, getdate()) + 2, 0)

getting results as like this

2014-10-30 13:00:00.000

but i don't need any dashes between dates i mean i am expecting results as shown below

20141030 13:00:00.000

can anyone help me on query please

Thanks,

Archana

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-10-30 : 12:16:34
If you are going to send the results to a client application, send it without any formatting as the datetime data type, and do the formatting in the client application/presentation layer. If you must format in SQL, here is an example:
REPLACE(CONVERT(VARCHAR(32), DATEADD(hour, DATEDIFF(hour, 0, GETDATE()) + 2, 0), 121), '-', '')
Go to Top of Page
   

- Advertisement -