all groups > dotnet web services > september 2006 >
You're in the

dotnet web services

group:

strange date behavior



strange date behavior Jeremy Chapman
9/27/2006 2:10:41 PM
dotnet web services: I've created a web service method which looks like
public MatchResult CheckMatch(MatchData MatchValues)

MatchData is a class defined as:
public class MatchData
{
public string GivenName;
public string FamilyName;
public DateTime BirthDate;
public string Gender;
}
When I call the web service, I set the BirthDate property to March 3, 1997,
and when I trace the soap call I see that the date is
"1997-03-02T16:00:00.0000000-08:00"
In my web service, I debug it and when I inspect the MatchData instance, I
see that the BirthDate property contains 1997-03-02 as the date and 16:00 as
the time. Now, the date is 1 day off. Anyone know what causes this and how
to fix it?

<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><CheckMatch
xmlns="http://mycompany.ca/WebServices"><MatchValues><PHN>9873835731</PHN><GivenName>JENNA</GivenName><FamilyName>BOWER</FamilyName><BirthDate>1997-03-02T16:00:00.0000000-08:00</BirthDate><Gender>F</Gender></MatchValues></CheckMatch></soap:Body></soap:Envelope>

Re: strange date behavior John Saunders
9/28/2006 7:19:18 AM
[quoted text, click to view]

This looks like a time zone problem. "March 3, 1997" in which timezone?
Pacific (-8)?

What's the offset from where you are to GMT? 13? So, maybe 1997-03-02T16:00
+ 13 = 1997-03-03T05:00?

I'm not completely sure, but this does seem like a timezone issue.

John

Re: strange date behavior Franklin M. Gauer III
9/29/2006 1:35:01 PM

Yes - depending on where your webserver is and where your client is - a
timezone conversion will be done. If the webserver is set to a different
timezone than your client - this will occur.

I'm not aware of a system setting that will prevent this from happening (if
you don't want it to happen - maybe someone else on the forums knows). We've
taken care of this in the past by writing functions that 'take away' this
effect when we pass dates up to our webservices.

--
Franklin M. Gauer III
Applications Development Manager
Integrated Companies, Inc.


[quoted text, click to view]
Re: strange date behavior Jeremy Chapman
10/5/2006 4:35:12 PM
Yes, it is a time zone issue, even though both machines are in the same time
zone and have the same system date.
I solved it in my class by converting it to universal time before storing
it.

public class MatchData
{
private DateTime dtBirthDate_m;
public string PHN;
public string GivenName;
public string FamilyName;
public string Gender;

public DateTime BirthDate
{
set
{
dtBirthDate_m = value.ToUniversalTime();
}
get
{
return dtBirthDate_m.ToLocalTime();
}
}

[System.Xml.Serialization.XmlIgnore]
public DateTime BirthDateUTC
{
set
{
dtBirthDate_m = value;
}
get
{
return dtBirthDate_m.ToUniversalTime();
}
}

}

[quoted text, click to view]

AddThis Social Bookmark Button