chinnusaccount
chinnusaccount

Reputation: 229

Convert datetime to yyyy-mm-dd:hh in SQL Server

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

Answers (3)

heretolearn
heretolearn

Reputation: 6545

If both input and result are in datetime format, you could just use substring to get the desired output.

Upvotes: 0

Naresh Pansuriya
Naresh Pansuriya

Reputation: 2045

can you tried this

SELECT REPLACE(CONVERT(VARCHAR(13), GETDATE(), 120), ' ', ':')

for more help please refer this link

Upvotes: 3

S. S. Rawat
S. S. Rawat

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

Related Questions