Solved

Culture specific date formatting?

Posted on 2004-08-27
6
1,179 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

773 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