Today we are going to learn a very simple and interesting concept which is used very little in the industry. It is about how to Display Dates in Different cultures FORMAT.
Let us assume that you want to display your current date and time in different formats in different geographic locations with the help of SQL Server. In SQL Server we have an option for function FORMAT which can make things easy for us.
For example, if you want to convert today’s date and time to any other culture’s date and time, you can easily do that by using the following query.
DECLARE @dt DATETIME = GETDATE(); SELECT FORMAT( @dt, 'F', 'en-US' ) 'US English' ,FORMAT( @dt, 'F', 'gu') 'Gujarati India' ,FORMAT( @dt, 'F', 'es' ) 'Spanish' ,FORMAT( @dt, 'F', 'is') 'Icelandic';
The result of the query will be as following:
Well, that’s it for today. You can use any other local and get your preferred results. I will be interesting to see what is your local and its result, why not paste that in the comment section below.
Here are my few recent videos and I would like to know what is your feedback about them. You can also subscribe to my YouTube Channel – SQL in Sixty Seconds.
- Copy Database – SQL in Sixty Seconds #169
- 9 SQL SERVER Performance Tuning Tips – SQL in Sixty Seconds #168
- Excel – Sum vs SubTotal – SQL in Sixty Seconds #167
- 3 Ways to Configure MAXDOP – SQL in Sixty Seconds #166
- Get Memory Details – SQL in Sixty Seconds #165
- Get CPU Details – SQL in Sixty Seconds #164
- Shutdown SQL Server Via T-SQL – SQL in Sixty Seconds #163
- SQL Server on Linux – SQL in Sixty Seconds 162
- Query Ignoring CPU Threads – SQL in Sixty Seconds 161
- Bitwise Puzzle – SQL in Sixty Seconds 160
- Find Expensive Queries – SQL in Sixty Seconds #159
- Case-Sensitive Search – SQL in Sixty Seconds #158
- Wait Stats for Performance – SQL in Sixty Seconds #157
- Multiple Backup Copies Stripped – SQL in Sixty Seconds #156
Reference:Â Pinal Dave (http://blog.SQLAuthority.com)
5 Comments. Leave new
I got the error of
Msg 195, Level 15, State 10, Line 2
‘FORMAT’ is not a recognized built-in function name.
What version of SQL Server are you using?
SQL Server 2012. You may need to revise the article to indicate which SQL Server version support the FORMAT function, thanks.
It should work for SQL Server 2012. I just tested and it worked great.
Ooops sorry, my apology. I just tested the SQL Server version is 2008 R2..