Filter datatable on date field on server pc problem

  • Thread starter Thread starter Willie wjb
  • Start date Start date
W

Willie wjb

Hi,

i have a client program that sends a filter expression to the server PC. On
that server PC this filter is put over a datatable and the result is send
back.

the server can be located on a PC with let's say ddmmyyyy windows date
format and the client has mmddyyyy.

when the filter expression send is "Date < #31/01/2003#", it will fail on
the server because the format for day and month is different.

is there a generic way to send a filter expression used with the
DataTable.Select command so that it works always whatever the windows
setting is?

or should i get the default windows date format from the server, send it to
the client which it should use?

thanks.
 
Hi Willie,

IF you cannot control the way that each part of the application you then
need to transform it on something generic, like a Tick, can you send the
data from the client to the server as a Tick ( this is defined as long ) ?
If so you could do this in the client:
DateTime.Ticks

and in the server:
new DateTime( tickCount )

in this way you don't care how the datetime is represented on the client or
on the server.

Hope this help,
 
the problem i have is that the client program is a sdk. So each user can
define it own where clauses...

does anybody know if the date format used by ado.net is restricted to US
format MM/dd/yyyy hh:mm:ss

i am doing several tests on different machines and found out that ado.net
only works with this US format, even on german pc's.

But when using i must be 100% sure that is behaves this way, and i can not
find any info for this on msdn.
 
Willie wjb said:
the problem i have is that the client program is a sdk. So each user can
define it own where clauses...

does anybody know if the date format used by ado.net is restricted to US
format MM/dd/yyyy hh:mm:ss

For jet sql data litereals #...# must always be in US format.
i am doing several tests on different machines and found out that ado.net
only works with this US format, even on german pc's.

You can use the function DateValue which is aware of international settings
in windows :

"SELECT * FROM tblTest WHERE test > DateValue('12/3/03')"

Hope this helps
greetings
 
ado.net does not contain a DateValue function

i use the rowfilter on a datatable that is in memory, no jet or sql
connection.
 
Hi,
[inline]

Willie wjb said:
ado.net does not contain a DateValue function

i use the rowfilter on a datatable that is in memory, no jet or sql
connection.

I don't know if this helps you much, but here are some conversions methods
that might give you some ideas As you already know, there is no way to
tell which format a date is in if the day is less or equal to 12. So
ussally the sender of the date converts the date to a fixed format or
specifies what the format is.

static string LocalToUS(string local)
{
System.Globalization.CultureInfo usc =
new System.Globalization.CultureInfo("en-US");

// default parsing uses current culture (local format)
DateTime dt = DateTime.Parse(local);

return dt.ToString(usc.DateTimeFormat.ShortDatePattern);
}

static string USToLocal(string us)
{
System.Globalization.CultureInfo usc =
new System.Globalization.CultureInfo("en-US");

DateTime dt = DateTime.Parse(us, usc);

return dt.ToString(System.Globalization.CultureInfo.
CurrentCulture.DateTimeFormat.ShortDatePattern);
}

Greetings
 
this one also passed my mind.
turn the server application into a english by changing the culture for it,
and tell the clients to use always the english format.

Thanks for your help.

BMermuys said:
Hi,
[inline]

Willie wjb said:
ado.net does not contain a DateValue function

i use the rowfilter on a datatable that is in memory, no jet or sql
connection.

I don't know if this helps you much, but here are some conversions methods
that might give you some ideas As you already know, there is no way to
tell which format a date is in if the day is less or equal to 12. So
ussally the sender of the date converts the date to a fixed format or
specifies what the format is.

static string LocalToUS(string local)
{
System.Globalization.CultureInfo usc =
new System.Globalization.CultureInfo("en-US");

// default parsing uses current culture (local format)
DateTime dt = DateTime.Parse(local);

return dt.ToString(usc.DateTimeFormat.ShortDatePattern);
}

static string USToLocal(string us)
{
System.Globalization.CultureInfo usc =
new System.Globalization.CultureInfo("en-US");

DateTime dt = DateTime.Parse(us, usc);

return dt.ToString(System.Globalization.CultureInfo.
CurrentCulture.DateTimeFormat.ShortDatePattern);
}

Greetings
to
US can
not send
the
result
is windows
date will
fail
 
Back
Top