Q

Inserting and retrieving dates in the dd/mm/yyyy HH24:mi:ss format

How do you insert or retrieve dates in the format dd/mm/yyyy HH24:mi:ss in SQL Server? Actually, I'm migrating a product from Oracle to SQL Server. The Convert function in SQL Server doesn't have a style like this and this is needed urgently. They have other styles, but I want this particular one.

To retrieve, roll your own format:

 select convert(varchar(50), getdate(),103)+' '+convert(varchar(50), getdate(),14)
To insert just ensure the DATEFORMAT is set correctly:
 create table #datetest ( datevalue datetime' ) SET DATEFORMAT DMY insert #datetest(datevalue) values('29/08/2002 21:20:03:787')

 

For More Information

This was first published in September 2002

Dig deeper on Microsoft SQL Server Installation

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchBusinessAnalytics

SearchDataCenter

SearchDataManagement

SearchAWS

SearchOracle

SearchContentManagement

SearchWindowsServer

Close