Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
From 112 to DATEPART
Message
 
 
To
24/01/2011 20:58:57
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01497298
Message ID:
01497300
Views:
52
This message has been marked as the solution to the initial question of the thread.
>I have this:
>
>
>SELECT CONVERT(CHAR(8),Hit.AddDate,112)
>
>
>It is good to return a 20110124 syntax. Now, I have another situation where I have pretty much the same query but I need to add two additional digits representing the hour. Basically, it goes like this:
>
>
>SELECT CONVERT(CHAR(4),YEAR(Hit.AddDate))+REPLACE(STR(MONTH(Hit.AddDate),2),' ','0')+
> REPLACE(STR(DAY(Hit.AddDate),2),' ','0')+REPLACE(STR(DATEPART(HOUR,Hit.AddDate),2),' ','0')
>
>
>What would be the replacement of 112 to obtain a syntax like 2011012412, which would represent the 12th hour for example.

Try
SELECT CONVERT(CHAR(8),Hit.AddDate,112) + CONVERT(CHAR(2), Hit.AddDate,108)
BTW, in SSMS highlight CONVERT and Press F1. It will give you all formats available for CONVERT.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform