Answer

How to change the date format in SQL with the style parameter

I am using SQL Server 2008. How can I change the date to 04/14/10?  Thanks.

    Requires Free Membership to View

 SELECT CONVERT(VARCHAR(255), [TTRHours], 109) FROM [GM].[dbo].[WORKING_SVR_CLOSED] WHERE TTRHours <> '-' Results: (No column name) Apr 14 2010 Apr 14 2010

All you should have to do is change the last parameter (style) in the CONVERT call.  You are currently using 109 which gives you a format of ‘mon dd yyyy’.  If you simply change the style parameter to 101 instead, you’ll get the format of mm/dd/yyyy.  If you change the style to 1, you’ll get mm/dd/yy. 

Check out the full list of styles and the full usage description of the CONVERT function.

Have a question for Karen Morton? Send an e-mail to editor@searchoracle.com

This was first published in May 2010

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: