How to change the date format in SQL Server 2008?

3

Currently my bank is in YYYY-DD-MM format I would like to in MM-DD-YYYY.

I found the SET DATEFORMAT only that is not the best option since I will have to add it in all querys .

Is it possible for me to configure it on my connection similar to what is done in MySQL ?? Or change it somewhere so I do not have to change in querys ?

    
asked by anonymous 28.04.2014 / 21:36

1 answer

3

If the idea is to use date literals in the queries, just use the ISO format: YYYY-MM-DD (year, month and day). This will be interpreted smoothly in any environment.

To format (or "print") dates for text in MM/DD/AAAA format you can use the CONVERT .

Example:

select convert(varchar, coluna_date, 101)

The same holds true for converting text in the specified format to a date:

select convert(datetime, coluna_varchar, 101)
    
28.04.2014 / 22:36