473,385 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

stupid american system

I am thoroughly frustrated with these seemingly unchangable settings in C#.
For example, fetching data from database sorted by date returns wrong order
(would be correct if I was using american date system). Same goes for
sorting datagrid (sorts dates and
decimal numbers - ie 31.12.2004 is sorted by first number instead of second
and 100.000,00 is treated as text ).
Is there a simple way of changing this or am I to write my own sorting
functions?
Nov 15 '05 #1
19 1446
I don't know if it can be changed, but the same applies to weekday
enumeration which puts sunday as the first day independent of the culture.
--
The hotmail account will most likely not be read, so please respond only
to the news group.
Nov 15 '05 #2
Sput <sp************@post.htnet.hr> wrote:
I am thoroughly frustrated with these seemingly unchangable settings in C#.
For example, fetching data from database sorted by date returns wrong order
(would be correct if I was using american date system). Same goes for
sorting datagrid (sorts dates and
decimal numbers - ie 31.12.2004 is sorted by first number instead of second
and 100.000,00 is treated as text ).
Is there a simple way of changing this or am I to write my own sorting
functions?


Before you start blaming C#:

1) C# is only the language, not the library

2) When you talk about "fetching data from database sorted by date" -
are you sorting by date on the database side, or on the client side? If
it's on the database side, how can it be C#'s fault?

3) Are you actually storing the dates in date columns in the database?

If it's on the client side, it should be possible to see all this in a
simple test program which just populates a data table without actually
going to a database. If you could produce such a program, I'll see what
I can do.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3

"Sput" <sp************@post.htnet.hr> wrote in message
news:c0**********@ls219.htnet.hr...
I am thoroughly frustrated with these seemingly unchangable settings in C#. For example, fetching data from database sorted by date returns wrong order (would be correct if I was using american date system). Same goes for
sorting datagrid (sorts dates and
decimal numbers - ie 31.12.2004 is sorted by first number instead of second and 100.000,00 is treated as text ).
Is there a simple way of changing this or am I to write my own sorting
functions?


Many routines 'read' the locale settings of the computer and the database.
How they will handle situations as you mentioned is often an interesting
joint-psychosis between the Framework types (and their methods) and Database
storeage types and DBA conventions and settings.

You can start-out by making sure your Windows version is the specific
language/locate version and local settings are setup correctly - as well as
the database. This works if you are only working in one locale all the time.

However, if, as I expect, you are working in a "dual" language/locale
environment, then the most proficient solution IS to create your own sorting
routines and conversion classes (types), as you will likely be continuely
fighting locale differences for some time to come.

-ralph
Nov 15 '05 #4
Actually, just add a calculated field like a string made from {fn
YEAR(...) } {fn MONTH(...)}
and then just sort on that column. Have the database do the work for you

JIM
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Sput <sp************@post.htnet.hr> wrote:
I am thoroughly frustrated with these seemingly unchangable settings in C#. For example, fetching data from database sorted by date returns wrong order (would be correct if I was using american date system). Same goes for
sorting datagrid (sorts dates and
decimal numbers - ie 31.12.2004 is sorted by first number instead of second and 100.000,00 is treated as text ).
Is there a simple way of changing this or am I to write my own sorting
functions?


Before you start blaming C#:

1) C# is only the language, not the library

2) When you talk about "fetching data from database sorted by date" -
are you sorting by date on the database side, or on the client side? If
it's on the database side, how can it be C#'s fault?

3) Are you actually storing the dates in date columns in the database?

If it's on the client side, it should be possible to see all this in a
simple test program which just populates a data table without actually
going to a database. If you could produce such a program, I'll see what
I can do.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #5
if anyone of repliers read this...
i have decide to use clarion's solution for dates
my local settings are set correctly
as for skeet, programs written in visual basic using same database respond
correctly
Nov 15 '05 #6

"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:op**************@msnews.microsoft.com...
I don't know if it can be changed, but the same applies to weekday
enumeration which puts sunday as the first day independent of the culture.


Is there any culture in which Sunday is not the first day of the week?

There may well be cultures that don't use the week, but...
Nov 15 '05 #7
The first day of *MY* week is now, and always has been MONDAY...
My pay period starts on MONDAY
Everyone in my organization has their calendar start as MONDAY = Work Week Starts... My pay period ends on SUNDAY
ad infinitum....
Chuck

"Michael A. Covington" <lo**@www.covingtoninnovations.com.for.address> wrote
in message news:ea**************@TK2MSFTNGP09.phx.gbl...
"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:op**************@msnews.microsoft.com...
I don't know if it can be changed, but the same applies to weekday
enumeration which puts sunday as the first day independent of the
culture.
Is there any culture in which Sunday is not the first day of the week?

There may well be cultures that don't use the week, but...

Nov 15 '05 #8
--
C#, .NET and Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
"Sput" <sp************@post.htnet.hr> wrote in message
news:c0**********@ls219.htnet.hr...
as for skeet, programs written in visual basic using same database respond
correctly
But that doesn't matter if the query pulling the dates casts them to string
or if the VB application is compensating for the unwanted sorting behaviour
and the dates really are stored as strings in the database / dataset.
Please give some details (i.e. a small sample app) that show the problem and
its context.

R.

Nov 15 '05 #9
But that is not a difference between nations. It seems to be a conflicting
usage within the United States. I have seen planning calendars that put
Monday first (so that Saturday and Sunday, which aren't supposed to have any
events, can share a box).

"Chuck Conlow" <lv******@earthlink.net> wrote in message
news:14*****************@newsread2.news.pas.earthl ink.net...
The first day of *MY* week is now, and always has been MONDAY...
My pay period starts on MONDAY
Everyone in my organization has their calendar start as MONDAY = Work
Week Starts...
My pay period ends on SUNDAY
ad infinitum....
Chuck

"Michael A. Covington" <lo**@www.covingtoninnovations.com.for.address>

wrote in message news:ea**************@TK2MSFTNGP09.phx.gbl...

"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:op**************@msnews.microsoft.com...
I don't know if it can be changed, but the same applies to weekday
enumeration which puts sunday as the first day independent of the

culture.

Is there any culture in which Sunday is not the first day of the week?

There may well be cultures that don't use the week, but...


Nov 15 '05 #10
Sput <sp************@post.htnet.hr> wrote:
if anyone of repliers read this...
i have decide to use clarion's solution for dates
my local settings are set correctly
as for skeet, programs written in visual basic using same database respond
correctly


But you still haven't really told us much about what the situation is.
If you could give us more details, we could see whether clarion's
solution is *actually* the most appropriate (which it may be) or
whether there's a simpler, more elegant solution. It would also help
other people in the same situation in the future.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #11
Michael,

I think Monday is the first day of the week in many Eastern European
cultures (at least this is true for Russia and Ukraine). Still, enumerations
cannot change the order of their items in accordance with current culture
just because they are sets of constants by nature. What *should* change
though if the CurrentCulture is set, say, to "ru-RU" is the behavior of
methods such as DayOfWeek which should now return 1 for Monday and 7 for
Sunday.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Michael A. Covington" <lo**@www.covingtoninnovations.com.for.address> wrote
in message news:ea**************@TK2MSFTNGP09.phx.gbl...

"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:op**************@msnews.microsoft.com...
I don't know if it can be changed, but the same applies to weekday
enumeration which puts sunday as the first day independent of the
culture.
Is there any culture in which Sunday is not the first day of the week?

There may well be cultures that don't use the week, but...


Nov 15 '05 #12
Dmitriy Lapshin [C# / .NET MVP] <x-****@no-spam-please.hotpop.com>
wrote:
I think Monday is the first day of the week in many Eastern European
cultures (at least this is true for Russia and Ukraine). Still, enumerations
cannot change the order of their items in accordance with current culture
just because they are sets of constants by nature. What *should* change
though if the CurrentCulture is set, say, to "ru-RU" is the behavior of
methods such as DayOfWeek which should now return 1 for Monday and 7 for
Sunday.


No, because DateTime.DayOfWeek (which I assume is what you were talking
about) returns a DayOfWeek. If it started returning values which
weren't in the DayOfWeek enumeration, things would go wrong pretty
quickly.

What I believe is *really* missing is a FirstDayOfWeek property in the
System.Globalization.Calendar class. However, it's not really that
simple - the first day of the week doesn't just depend on culture, it
depends on context. A salesman looking at his calendar is likely to
want Monday as the first day of the week. Others (myself included) are
likely to want Sunday as the first day of the week.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #13
Jon,

The DateTimeFormatInfo class has the FirstDayOfWeek property which can be
set as well as read. I haven't used it though so I am not sure it does the
job. The MSDN help is very brief on this topic.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP***********************@msnews.microsoft.co m...
Dmitriy Lapshin [C# / .NET MVP] <x-****@no-spam-please.hotpop.com>
wrote:
I think Monday is the first day of the week in many Eastern European
cultures (at least this is true for Russia and Ukraine). Still, enumerations cannot change the order of their items in accordance with current culture just because they are sets of constants by nature. What *should* change
though if the CurrentCulture is set, say, to "ru-RU" is the behavior of
methods such as DayOfWeek which should now return 1 for Monday and 7 for
Sunday.


No, because DateTime.DayOfWeek (which I assume is what you were talking
about) returns a DayOfWeek. If it started returning values which
weren't in the DayOfWeek enumeration, things would go wrong pretty
quickly.

What I believe is *really* missing is a FirstDayOfWeek property in the
System.Globalization.Calendar class. However, it's not really that
simple - the first day of the week doesn't just depend on culture, it
depends on context. A salesman looking at his calendar is likely to
want Monday as the first day of the week. Others (myself included) are
likely to want Sunday as the first day of the week.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 15 '05 #14
Dmitriy Lapshin [C# / .NET MVP] <x-****@no-spam-please.hotpop.com>
wrote:
The DateTimeFormatInfo class has the FirstDayOfWeek property which can be
set as well as read. I haven't used it though so I am not sure it does the
job. The MSDN help is very brief on this topic.


Goodo - I somehow missed that on previous searches for it (having found
the one on the Calendar control).

Of course, people then need to take note of that property, but at least
it's there.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #15
Application is rather large and I noticed problem when I started writting
reports for it.

Data field in database is datetime. When opened in access it can be sorted
properly in it.

When I get it into C#, I use command as
sql="SELECT code,name,item1,item2,date WHERE blah blah ORDER by date"

same happens when using GROUP BY date

In datagrid, as I have asked several times everywhere, which is populated by
data
from same database, when I click on column that contains dates or decimal
numbers, it
is sorted just by "dd" of "dd.MM.yyyy", while decimal is sorted by "#" of
"#,##0.00"

I have tried formating date columns to "dd.MM.yyyy", set my culture info to
current thread etc etc.
Current solution:
grab data from datatable to array, sort it there, then populate
datagrid.Easy, but possibly slow
Nov 15 '05 #16
Sput <sp************@post.htnet.hr> wrote:
Application is rather large and I noticed problem when I started writting
reports for it.

Data field in database is datetime. When opened in access it can be sorted
properly in it.

When I get it into C#, I use command as
sql="SELECT code,name,item1,item2,date WHERE blah blah ORDER by date"

same happens when using GROUP BY date
If you're doing that, it should correctly be sorted to start with,
before you tell the grid to sort the results at all.
In datagrid, as I have asked several times everywhere, which is populated by
data from same database, when I click on column that contains dates or decimal
numbers, it is sorted just by "dd" of "dd.MM.yyyy", while decimal is sorted by "#" of
"#,##0.00"


It sounds like it's DataGrid's (or possibly even DataView's) sorting
that's at fault then, sorting it by formatted string rather than by
actual value. I'll look into it a bit... it sounds like there's no need
for an actual database to be involved at all.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #17
Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
In datagrid, as I have asked several times everywhere, which is populated by
data from same database, when I click on column that contains dates or decimal
numbers, it is sorted just by "dd" of "dd.MM.yyyy", while decimal is sorted by "#" of
"#,##0.00"


It sounds like it's DataGrid's (or possibly even DataView's) sorting
that's at fault then, sorting it by formatted string rather than by
actual value. I'll look into it a bit... it sounds like there's no need
for an actual database to be involved at all.


Hmm... I can't reproduce the problem. Here's an example which shows a
DataGrid which allows sorting of DateTimes and decimals with no
problems:

using System;
using System.Data;
using System.Windows.Forms;
using System.Drawing;

public class Test
{
[STAThread]
static void Main(string[] args)
{
DataTable table = new DataTable();
table.Columns.Add("ID", typeof(int));
table.Columns.Add("DateTime", typeof(DateTime));
table.Columns.Add("Decimal", typeof(decimal));

for (int i=0; i < 20; i++)
{
table.Rows.Add(new object[]{i,
MakeRandomDateTime(),
MakeRandomDecimal()});
}

Form form = new Form();
form.Text = "DataGrid test";
form.Size = new Size (300, 600);
DataGrid grid = new DataGrid();
grid.DataSource = table;
grid.Dock = DockStyle.Fill;
form.Controls.Add(grid);
Application.Run(form);
}

static Random rng = new Random();
static DateTime MakeRandomDateTime()
{
return new DateTime (rng.Next(5)+1998,
rng.Next(12)+1,
rng.Next(25)+1,
rng.Next(24),
rng.Next(60),
rng.Next(60));
}

static decimal MakeRandomDecimal()
{
// Horrible, I know...
int whole = rng.Next (10000);
int fractional = rng.Next(10000);
string combined = String.Format("{0}.{1:d4}",
whole,
fractional);
return decimal.Parse(combined);
}
}
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #18
Thank you, your example sorts properly.
Nov 15 '05 #19
Sput <sp************@post.htnet.hr> wrote:
Thank you, your example sorts properly.


So, can you work out what the difference between my example and your
application is?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Blair Dickinson | last post by:
--BF63.D._B.D Content-Type: text/plain; Content-Transfer-Encoding: quoted-printable EXCLUSIVELY ON CD-ROM The 2004 edition of The American Medical Directory & Physicians Guide has= just...
0
by: Pat | last post by:
----E7AC83C60895C0C204C Content-Type: text/html; Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled...
2
by: Lampa Dario | last post by:
Hi, where is this stupid error in this program? When I execute it, i receive a segmentation fault error. #include <stdio.h> int main(int argc, char *argv, char *env) { int i=0; int l=0; int...
3
by: Amil | last post by:
I must be missing something very simple. I've had a web site running for a long time (anonymous access). Web.config authentication is original (anyone gets in): <authentication mode="Windows"...
6
by: Adam Smith | last post by:
I have posted this and similar questions repeatedly and can't even raise a single response. I am being led to believe that this then 'Must be a stupid question' although people say that there is no...
6
by: thechaosengine | last post by:
Hi guys, I'm developing a web app on a UK computer. When I put a date into a textbox, its in the format DD/MM/YY. The DateTime object takes that in and handles in perfectly. Now, I need to...
9
by: Simon Harvey | last post by:
Hi all, I'm having a bit of a problem working with dates. My computer is british, but I'm developing an american application so I therefore need to use american dates. But I can't get my...
15
by: sparks | last post by:
We get more and more data done in excel and then they want it imported into access. The data is just stupid....values of 1 to 5 we get a lot of 0's ok that alright but 1-jan ? we get colums...
4
by: stj911 | last post by:
http://counterpunch.org/rahni04072007.html Test Tube Zealots: The American Chemical Society Terminates the Membership of Chemists from Iran By DAVID N. RAHNI The American Chemical Society...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.