Ask the Expert

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

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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: