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
|