Solved

Culture specific date formatting?

Posted on 2004-08-27
6
1,175 Views
Last Modified: 2012-05-05
I would like to query some tables and return culture-aware date values.

For instance,

I have three columns BegDate, EndDate, and Year.

4/1,
8/31,
2000

are the values respectively.

In some cultures, the month / date is represented as date . month.
So, 4/1 becomes 1.4

Is there anyway to pull these date values for the specific culture that the user has set, using just SQL?
0
Comment
Question by:gregasm
  • 2
  • 2
  • 2
6 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 11918483
>>Is there anyway to pull these date values for the specific culture that the user has set, using just SQL?<<
No.  This is best handled in the front-end.  You can set the format using CONVERT and setting the style property.  However this is manual process.  In other words to get the german format you would use something like this:
CONVERT(varchar(10), GETDATE(), 104) --> 27.08.2004

Of course, if you wanted you could pass the style in from the front-end.
0
 
LVL 15

Expert Comment

by:jdlambert1
ID: 11918651
You could use the DATEPART (or other date/time functions like MONTH or DATENAME) to parse a datetime value, CAST each piece you parse to a varchar datatype, and concatenate them together (with the plus symbol), to form any format you want.

You could define this formatting in a view, in which case, you'd need a separate view for each cultural variation.

You could also define the formatting in a stored procedure, in which case, you could have one stored procedure per cultural variation, or you could have a single stored procedure that could output different formats depending on a culture variable that you pass in to it.
0
 
LVL 8

Author Comment

by:gregasm
ID: 11918707
wow, jdlambert1, I feel carpal tunnel just thinking about all that work.. hahah =]]

I'm looking for a simple one, like equivalent to

Format("4/1/2003", "General Date")

Which would output different string values depending on the cultural settings of the particular windows machine...
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 15

Assisted Solution

by:jdlambert1
jdlambert1 earned 150 total points
ID: 11918982
The only simple solution is very limited, and that's the Style parameter of the CONVERT function that Anthony cited above. For available styles, open SQL Server Books Online and go to "Convert" in the index, then choose the "CAST and CONVERT" topic.

A word of warning: Test CONVERT's output, don't just rely on the style examples in BOL. You can use:

SELECT Convert(varchar(22), GetDate(), 101)

and replace 101 with the various style codes listed.
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 350 total points
ID: 11921435
>>Which would output different string values depending on the cultural settings of the particular windows machine...<<
Think about it this way:  Cultural settings for which computer?  The server that is half the way around the world or the client?  Again, detecting the cultural settings is best handled at the client level.
0
 
LVL 8

Author Comment

by:gregasm
ID: 11922478
tha'ts a great point,.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now