Up From The Ashes

June 2009 Entries

Date Without Time When Serializing

I'm serializing a class in .NET and have a DateTime field.  It's getting serialized as:

2009-11-01T00:00:00

When what I really want is something without the time like this:

2009-11-01

Brad Abrams has a great post that has how to do this (plus a lot more).  Simply add this attribute to the property:

[XmlElementAttribute(DataType="date")]

This is probably basic to some, but was helpful to me.