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.

    Requires Free Membership to View

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

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.