From: Mark B on
Our webservice from a server is Florida is returning date strings in the
format:

"04/10/2009 2:12:25 p.m.|"

i.e. "mm/dd/yyyy hh:nn:ss a.m/p.m.", that is April 10, 2009


However when we consume the webservice via a local C# app, if the app is in
New Zealand, it treats the date as being October 4, 2009 since New Zealand
uses "dd/mm/yyyy hh:nn:ss a.m/p.m.", not "mm/dd/yyyy hh:nn:ss a.m/p.m.".


What's the best way for the webservice to return a DateTime value so it is
understood no matter where in the world it is consumed?









From: Armin Zingler on
Mark B schrieb:
> Our webservice from a server is Florida is returning date strings in the
> format:
>
> "04/10/2009 2:12:25 p.m.|"
>
> i.e. "mm/dd/yyyy hh:nn:ss a.m/p.m.", that is April 10, 2009
>
>
> However when we consume the webservice via a local C# app, if the app is in
> New Zealand, it treats the date as being October 4, 2009 since New Zealand
> uses "dd/mm/yyyy hh:nn:ss a.m/p.m.", not "mm/dd/yyyy hh:nn:ss a.m/p.m.".
>
>
> What's the best way for the webservice to return a DateTime value so it is
> understood no matter where in the world it is consumed?

How do you convert the String to DateTime? Try DateTime.ParseExact
instead (note that month=MM (capitals) and minutes=mm).


--
Armin

From: Mark B on
Thanks. I'll look into how the local C# app is parsing.

I figured the "MM" too when "mm" was not working.

I'm thinking I might use the following in the webservice in case the webhost
people in Florida decide to change the format of their datetime. Otherwise
if I used parse exact it might not work if they changed their format:


Function fWsDateFormat(ByVal dtRawDate As Object) As String

'Convert date time to standardized string
'---------------------------------------------
Dim strDateTimeStringFormat As String = "yyyy-MM-dd hh:mm:ss tt"
If dtRawDate.ToString = "" Then
Return ""
End If
Return Format(dtRawDate, strDateTimeStringFormat)

End Function


Hopefully then no matter which country the app was in, it would interpret
the date the same.






"Armin Zingler" <az.nospam(a)freenet.de> wrote in message
news:OZ9MNfmMKHA.5776(a)TK2MSFTNGP02.phx.gbl...
> Mark B schrieb:
>> Our webservice from a server is Florida is returning date strings in the
>> format:
>>
>> "04/10/2009 2:12:25 p.m.|"
>>
>> i.e. "mm/dd/yyyy hh:nn:ss a.m/p.m.", that is April 10, 2009
>>
>>
>> However when we consume the webservice via a local C# app, if the app is
>> in
>> New Zealand, it treats the date as being October 4, 2009 since New
>> Zealand
>> uses "dd/mm/yyyy hh:nn:ss a.m/p.m.", not "mm/dd/yyyy hh:nn:ss
>> a.m/p.m.".
>>
>>
>> What's the best way for the webservice to return a DateTime value so it
>> is
>> understood no matter where in the world it is consumed?
>
> How do you convert the String to DateTime? Try DateTime.ParseExact
> instead (note that month=MM (capitals) and minutes=mm).
>
>
> --
> Armin
>

From: Armin Zingler on
Mark B schrieb:
> Thanks. I'll look into how the local C# app is parsing.
>
> I figured the "MM" too when "mm" was not working.
>
> I'm thinking I might use the following in the webservice in case the webhost
> people in Florida decide to change the format of their datetime. Otherwise
> if I used parse exact it might not work if they changed their format:
>
>
> Function fWsDateFormat(ByVal dtRawDate As Object) As String
>
> 'Convert date time to standardized string
> '---------------------------------------------
> Dim strDateTimeStringFormat As String = "yyyy-MM-dd hh:mm:ss tt"
> If dtRawDate.ToString = "" Then
> Return ""
> End If
> Return Format(dtRawDate, strDateTimeStringFormat)
>
> End Function
>
> Hopefully then no matter which country the app was in, it would interpret
> the date the same.
>


In what way does this help solve the aforementioned problem? This
function converts into a String but not the other way round.

How will you know the new format if it will be changed? Isn't it
possible to get the values as a DateTime or DateTimeOffset object? When
working with dates/times, they should not be held in Strings. Only the
user interface frontend should deal with a certain format and the
conversion from/to String.

It's more secure to narrow down types as good as possible. Is there a
reason why the argument's type is 'Object'? If you pass a Form it will
fail at runtime. With a DateTime object, you can go the straight way
by calling dtRawDate.ToString(<format>).


See also "Working with base types":
http://msdn.microsoft.com/en-us/library/7wchwf6k.aspx



--
Armin
From: bruce barker on
you should use the gmt time format (RFC 1123). Also be sure to convert
local date/time to gmt:

var date = DateTime.Now;
var utcdate = new DateTimeOffset(date,
TimeZoneInfo.Local.GetUtcOffset(date1);
var webDate = utcDate.ToUniversalTime().ToString("r");

-- bruce (sqlwork.com)

Mark B wrote:
> Our webservice from a server is Florida is returning date strings in the
> format:
>
> "04/10/2009 2:12:25 p.m.|"
>
> i.e. "mm/dd/yyyy hh:nn:ss a.m/p.m.", that is April 10, 2009
>
>
> However when we consume the webservice via a local C# app, if the app is
> in New Zealand, it treats the date as being October 4, 2009 since New
> Zealand uses "dd/mm/yyyy hh:nn:ss a.m/p.m.", not "mm/dd/yyyy hh:nn:ss
> a.m/p.m.".
>
>
> What's the best way for the webservice to return a DateTime value so it
> is understood no matter where in the world it is consumed?
>
>
>
>
>
>
>
>
>