Wednesday, March 28, 2012

Where does the short date format come from?

I've hit a snag with an application I wrote because of the differing
date formats in different countries.

It's a set of pages that make calls to a COM object that I have wrapped
in a web service. The COM object isn't mine, and it wants to receive
dates in a short date format, and it seems to inherit the localized
settings of it's host machine. The machine with that service/COM object
is in Canada and is set to use dd/mm/yyyy date format, and the server
with the pages is in the US and is using mm/dd/yyyy.

When I make calls to the web service, I'm converting the date sent in
using Date.ToShortDate (which I realize now was a bad decision). I
figured I could get around this by changing the pages server to use
dd/mm/yyyy via the Control Panel, but it seems to have no effect on the
short date being passed to the web service.

Does asp.net have a setting elsewhere that sets this? Any other ideas
(that don't require a code change)? Thanks!

MattToShortDateString uses the current thread's CultureInfo object. That class
defines the structure of dates, times, numbers, currency and a few things
about text. Every thread has one.

Since this issue also affects validators, take a look at the section
"Validators support for globalization" in my article at
http://aspalliance.com/699. It will give you specifics.

-- Peter Blum
www.PeterBlum.com
Email: PLBlum@.PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"MattB" <somedudeus@.yahoo.com> wrote in message
news:3m1jlsF152sddU1@.individual.net...
> I've hit a snag with an application I wrote because of the differing date
> formats in different countries.
> It's a set of pages that make calls to a COM object that I have wrapped in
> a web service. The COM object isn't mine, and it wants to receive dates in
> a short date format, and it seems to inherit the localized settings of
> it's host machine. The machine with that service/COM object is in Canada
> and is set to use dd/mm/yyyy date format, and the server with the pages is
> in the US and is using mm/dd/yyyy.
> When I make calls to the web service, I'm converting the date sent in
> using Date.ToShortDate (which I realize now was a bad decision). I figured
> I could get around this by changing the pages server to use dd/mm/yyyy via
> the Control Panel, but it seems to have no effect on the short date being
> passed to the web service.
> Does asp.net have a setting elsewhere that sets this? Any other ideas
> (that don't require a code change)? Thanks!
> Matt
Thanks! I think that set us straight (or at least in the right direction).

Matt

Peter Blum wrote:
> ToShortDateString uses the current thread's CultureInfo object. That class
> defines the structure of dates, times, numbers, currency and a few things
> about text. Every thread has one.
> Since this issue also affects validators, take a look at the section
> "Validators support for globalization" in my article at
> http://aspalliance.com/699. It will give you specifics.
> -- Peter Blum
> www.PeterBlum.com
> Email: PLBlum@.PeterBlum.com
> Creator of "Professional Validation And More" at
> http://www.peterblum.com/vam/home.aspx
> "MattB" <somedudeus@.yahoo.com> wrote in message
> news:3m1jlsF152sddU1@.individual.net...
>>I've hit a snag with an application I wrote because of the differing date
>>formats in different countries.
>>
>>It's a set of pages that make calls to a COM object that I have wrapped in
>>a web service. The COM object isn't mine, and it wants to receive dates in
>>a short date format, and it seems to inherit the localized settings of
>>it's host machine. The machine with that service/COM object is in Canada
>>and is set to use dd/mm/yyyy date format, and the server with the pages is
>>in the US and is using mm/dd/yyyy.
>>
>>When I make calls to the web service, I'm converting the date sent in
>>using Date.ToShortDate (which I realize now was a bad decision). I figured
>>I could get around this by changing the pages server to use dd/mm/yyyy via
>>the Control Panel, but it seems to have no effect on the short date being
>>passed to the web service.
>>
>>Does asp.net have a setting elsewhere that sets this? Any other ideas
>>(that don't require a code change)? Thanks!
>>
>>Matt
>
Couldn't you do some custom DateTime Format strings before you pass th
value along to the web service? If you search Visual Studio fo
"format datetime", there are some examples...

Ralp

--
rvira
----------------------
rviray's Profile: http://www.msusenet.com/member.php?userid=421
View this thread: http://www.msusenet.com/t-187097517

0 comments:

Post a Comment