Reputation: 229
How can I convert yyyy-mm-dd:hh:mm:ss
to yyyy-mm-dd:hh
in SQL Server?
I want to convert 2013-04-30:10:34:23
to 2013-04-30:10:00:00
?
Please help me to resolve this issue.
Upvotes: 2
Views: 7132
Reputation: 6545
If both input and result are in datetime
format, you could just use substring
to get the desired output.
Upvotes: 0
Reputation: 2045
can you tried this
SELECT REPLACE(CONVERT(VARCHAR(13), GETDATE(), 120), ' ', ':')
for more help please refer this link
Upvotes: 3
Reputation: 6111
Read this
, this will help you how to convert or short any date format in SQL sever
Example
The following script uses the CONVERT() function to display different formats. We will use the GETDATE() function to get the current date/time:
CONVERT(VARCHAR(19),GETDATE())
CONVERT(VARCHAR(10),GETDATE(),10)
CONVERT(VARCHAR(10),GETDATE(),110)
CONVERT(VARCHAR(11),GETDATE(),6)
CONVERT(VARCHAR(11),GETDATE(),106)
CONVERT(VARCHAR(24),GETDATE(),113)
The result would look something like this:
Nov 04 2011 11:45 PM
11-04-11
11-04-2011
04 Nov 11
04 Nov 2011
04 Nov 2011 11:45:34:243
Upvotes: -1