Solved

Culture specific date formatting?

Posted on 2004-08-27
6
1,184 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

734 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