How to format a date in SQL Server 2008

EDIT:

How to format date in sql sevrer with dd-mm-yyyy format in yyyy-mm-dd format. This format is not listed in sql server, but similar format is available yyyy / mm / dd

Is there such a feature in SQL Server 2008 or 2005

+2


a source to share


3 answers


SELECT CONVERT(CHAR(10), GetDate(), 126) 

      

Using CHAR (10), this will chop off some of the time you don't need.



ps. Replace GetDate () with the date you need to convert

EDIT: Cast and Convert "shows this conversion.

+1


a source


If you have a real "datetime" column, the date is not stored in any particular string format, but in (fixed) binary format.



Only when displaying the results in Query Analyzer (or Management Studio) is the internal format converted to a string. If you ask for this column, you will return a real date (not a string).

0


a source


You said you stored the value in string format, so first you need to convert it back to a date using the convert (date, columnname, 103) command, then you can format it as you like .

An example of choosing a format (convert (date, "29 -03-2019", 103), "yyyy-mm-dd")

it converts a date string in the format dd-mm-yyyy to a date string yyyy-mm-dd.

0


a source







All Articles