Crystal Reports & SQL Reporting Services Training Consultants
Account Log in:
Username:
Password:
A man who does not think for himself does not think at all. Thinking cannot be done by proxy
 
Institute of IT Trainers - Freelance Trainer of the Year 2006 & 2009
Liverpool Business Connect Member
  Maximum Impact Solutions Limited - Reporting Solutions, Creating Answers
Reporting Solutions - Creating Answers, Crystal Reports, Dashboarding (Xcelsius) & SQL Reporting Services

The Maximum Impact Solutions Blog Feed ME!!!!

07
July

How Do I Change the format of a DateTime field in SQL?

A client has just asked me how does one format a datetime field in SQL to display the date in the format dd/mm/yyyy?

The SQL Code to convert a field to a specified date time format is:

CONVERT(Data Type(length), field to be converted, Numeric format Code)


So to display todays date in the format dd/mm/yyyy:

CONVERT(varchar(25), Getdate(), 103)


There are a number of different numerical codes, but below are some further SQL code examples of SQL code formatting codes using the current date:


 SQL Code

 Resultant Format

 CONVERT(varchar(25), Getdate(), ) Jul 07 2010 14:48 PM
 CONVERT(varchar(25), Getdate(), 102) 2010.07.07
 CONVERT(varchar(25), Getdate(), 106) 07 Jul 2010
 CONVERT(varchar(25), Getdate(), 113) 07 Jul 2010 14:48:13:235
 CONVERT(varchar(25), Getdate(), 108)14:48:13




If you have any questions, or need any assistance, please do not hesitate to Contact Us

MAKE A COMMENT

Name *

Email Address *

Comment *

To prove you are human what is:

27 + 48 =