Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Culture specific date formatting?

Posted on 2004-08-27
6
Medium Priority
?
1,189 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
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
LVL 15

Assisted Solution

by:jdlambert1
jdlambert1 earned 600 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 1400 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
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 setup several different housekeeping processes for a SQL Server.

927 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