473,854 Members | 1,469 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date Formate when using ds.WriteXml

I have a Table in a Typed Dataset which contains a Date field called
EventDate.
I've ensured that the field is defined as Date as opposed to DateTime in the
Typed Dataset.

When I generate an xml file from an instance of this typed dataset using the
ds.WriteXml method, all the dates come out formatted as follows:

<EventDate>20 04-01-26T00:00:00.000 0000-05:00</EventDate>

which is the DateTime datatype of the W3C XML Schema Part 2: Datatypes

I want the dates to come out as

<EventDate>20 04-01-26</EventDate>

which is the Date datatype of the W3C XML Schema Part 2: Datatypes

How to I force the WriteXml method to output dates as the Date datatype as
opposed to the DateTime datatype?
Nov 12 '05 #1
4 7636
"Robert Scarborough" <r0************ ******@hotmail. com> wrote in message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
I have a Table in a Typed Dataset which contains a Date field called
EventDate. I've ensured that the field is defined as Date as opposed
to DateTime in the Typed Dataset. : : <EventDate>20 04-01-26T00:00:00.000 0000-05:00</EventDate>

which is the DateTime datatype of the W3C XML Schema Part 2: Datatypes

I want the dates to come out as

<EventDate>20 04-01-26</EventDate>


I think you'll need to use an XmlTextWriter subclass to intercept the output
of WriteXml( ) when it's writing these dates. Here's a XmlTextWriter to get
you started,

- - - DsDateFilterXml TextWriter.cs
// . . .
public class DsDateFilterXml TextWriter : XmlTextWriter
{
private string watchElement;
private bool onWatch;

public DsDateFilterXml TextWriter( TextWriter writer, string watchElement) : base( writer)
{
this.watchEleme nt = watchElement;
}

public override void WriteStartEleme nt( string prefix, string localName, string ns)
{
base.WriteStart Element( prefix, localName, ns);
if ( 0 == string.Compare( this.watchEleme nt, localName))
{
onWatch = true;
}
}

public override void WriteString( string text)
{
if ( onWatch )
{
try
{
DateTime dt = DateTime.Parse( text);
text = dt.ToString( "yyyy-MM-dd");
}
catch ( FormatException )
{
;
}
onWatch = false;
}
base.WriteStrin g( text);
}
}
// . . .
dataSet1.WriteX ml( new DsDateFilterXml TextWriter( Console.Out, "EventDate" ) );
// . . .
- - -

The DataSet represents the value with the time zone to ensure it's unambiguous
what date it represents (for instance, at 11 p.m. in Chicago, the date you've
given is January 25, but in London, England, it's January 26).
Derek Harmon
Nov 12 '05 #2
Thanks for the very robust reply.

I understand that the DateTime format contains the time zone information.
But there are many situations where the time zone information isn't
appropriate and just the simple Date is necessary. The W3C recognizes this
by the fact that they also define a simple Date-only format (Namely "Date")
as an alternative to DateTime.

I wish Microsoft would have given us some kind of property to set to control
whether dates are spit out as DateTime or Date rather than forcing DateTime.
In our particular application, we need to send to customers around the
world, lists of dates indicating when bank holidays occur around the world.
It doesn't make sense to have my particular time zone information (Eastern
Standard) included in a list of bank holidays for Tokyo.

The problem with your suggestion for my particular case is that I also want
to be able to use the ds.WriteXmlSche ma method to send my clients a schema
which matches my data. So I would also have to do some fiddling with that
to match the changes you've suggested. I suppose I could just create a new
string field in my Datatable to contain the string value of the date, but
then the schema would define that field as a String rather that a Date.
Perhaps your suggestion is my only option and I'll have to also have code to
modify the schema and code to make sure everything is in synch - yecht.

I hope I don't sound like I'm complaining to you. I just hope someone from
Microsoft is watching.

Thanks again for your help.
Bob Scarborough
"Derek Harmon" <lo*******@msn. com> wrote in message
news:uj******** ******@TK2MSFTN GP15.phx.gbl...
"Robert Scarborough" <r0************ ******@hotmail. com> wrote in message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
I have a Table in a Typed Dataset which contains a Date field called
EventDate. I've ensured that the field is defined as Date as opposed
to DateTime in the Typed Dataset.

: :
<EventDate>20 04-01-26T00:00:00.000 0000-05:00</EventDate>

which is the DateTime datatype of the W3C XML Schema Part 2: Datatypes

I want the dates to come out as

<EventDate>20 04-01-26</EventDate>


I think you'll need to use an XmlTextWriter subclass to intercept the

output of WriteXml( ) when it's writing these dates. Here's a XmlTextWriter to get you started,

- - - DsDateFilterXml TextWriter.cs
// . . .
public class DsDateFilterXml TextWriter : XmlTextWriter
{
private string watchElement;
private bool onWatch;

public DsDateFilterXml TextWriter( TextWriter writer, string watchElement) : base( writer) {
this.watchEleme nt = watchElement;
}

public override void WriteStartEleme nt( string prefix, string localName, string ns) {
base.WriteStart Element( prefix, localName, ns);
if ( 0 == string.Compare( this.watchEleme nt, localName))
{
onWatch = true;
}
}

public override void WriteString( string text)
{
if ( onWatch )
{
try
{
DateTime dt = DateTime.Parse( text);
text = dt.ToString( "yyyy-MM-dd");
}
catch ( FormatException )
{
;
}
onWatch = false;
}
base.WriteStrin g( text);
}
}
// . . .
dataSet1.WriteX ml( new DsDateFilterXml TextWriter( Console.Out, "EventDate" ) ); // . . .
- - -

The DataSet represents the value with the time zone to ensure it's unambiguous what date it represents (for instance, at 11 p.m. in Chicago, the date you've given is January 25, but in London, England, it's January 26).
Derek Harmon

Nov 12 '05 #3
For relevant discussion, see
http://blogs.msdn.com/brada/archive/...13/112784.aspx

"Robert Scarborough" <r0************ ******@hotmail. com> wrote in message
news:%2******** *******@TK2MSFT NGP14.phx.gbl.. .
Thanks for the very robust reply.

I understand that the DateTime format contains the time zone information.
But there are many situations where the time zone information isn't
appropriate and just the simple Date is necessary. The W3C recognizes
this
by the fact that they also define a simple Date-only format (Namely
"Date")
as an alternative to DateTime.

I wish Microsoft would have given us some kind of property to set to
control
whether dates are spit out as DateTime or Date rather than forcing
DateTime.
In our particular application, we need to send to customers around the
world, lists of dates indicating when bank holidays occur around the
world.
It doesn't make sense to have my particular time zone information (Eastern
Standard) included in a list of bank holidays for Tokyo.

The problem with your suggestion for my particular case is that I also
want
to be able to use the ds.WriteXmlSche ma method to send my clients a
schema
which matches my data. So I would also have to do some fiddling with that
to match the changes you've suggested. I suppose I could just create a
new
string field in my Datatable to contain the string value of the date, but
then the schema would define that field as a String rather that a Date.
Perhaps your suggestion is my only option and I'll have to also have code
to
modify the schema and code to make sure everything is in synch - yecht.

I hope I don't sound like I'm complaining to you. I just hope someone
from
Microsoft is watching.

Thanks again for your help.
Bob Scarborough
"Derek Harmon" <lo*******@msn. com> wrote in message
news:uj******** ******@TK2MSFTN GP15.phx.gbl...
"Robert Scarborough" <r0************ ******@hotmail. com> wrote in message

news:%2******** ********@tk2msf tngp13.phx.gbl. ..
> I have a Table in a Typed Dataset which contains a Date field called
> EventDate. I've ensured that the field is defined as Date as opposed
> to DateTime in the Typed Dataset.

: :
> <EventDate>20 04-01-26T00:00:00.000 0000-05:00</EventDate>
>
> which is the DateTime datatype of the W3C XML Schema Part 2: Datatypes
>
> I want the dates to come out as
>
> <EventDate>20 04-01-26</EventDate>


I think you'll need to use an XmlTextWriter subclass to intercept the

output
of WriteXml( ) when it's writing these dates. Here's a XmlTextWriter to

get
you started,

- - - DsDateFilterXml TextWriter.cs
// . . .
public class DsDateFilterXml TextWriter : XmlTextWriter
{
private string watchElement;
private bool onWatch;

public DsDateFilterXml TextWriter( TextWriter writer, string

watchElement) : base( writer)
{
this.watchEleme nt = watchElement;
}

public override void WriteStartEleme nt( string prefix, string

localName, string ns)
{
base.WriteStart Element( prefix, localName, ns);
if ( 0 == string.Compare( this.watchEleme nt, localName))
{
onWatch = true;
}
}

public override void WriteString( string text)
{
if ( onWatch )
{
try
{
DateTime dt = DateTime.Parse( text);
text = dt.ToString( "yyyy-MM-dd");
}
catch ( FormatException )
{
;
}
onWatch = false;
}
base.WriteStrin g( text);
}
}
// . . .
dataSet1.WriteX ml( new DsDateFilterXml TextWriter( Console.Out,

"EventDate" ) );
// . . .
- - -

The DataSet represents the value with the time zone to ensure it's

unambiguous
what date it represents (for instance, at 11 p.m. in Chicago, the date

you've
given is January 25, but in London, England, it's January 26).
Derek Harmon


Nov 12 '05 #4
Thanks for the info. It makes for interesting reading.

On the one hand, its nice to see that I'm not alone in my problems.

On the other hand, its not nice to see that Microsoft doesn't have a
solution.

Bob Scarborough

"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote in message
news:uL******** ******@tk2msftn gp13.phx.gbl...
For relevant discussion, see
http://blogs.msdn.com/brada/archive/...13/112784.aspx

"Robert Scarborough" <r0************ ******@hotmail. com> wrote in message
news:%2******** *******@TK2MSFT NGP14.phx.gbl.. .
Thanks for the very robust reply.

I understand that the DateTime format contains the time zone information. But there are many situations where the time zone information isn't
appropriate and just the simple Date is necessary. The W3C recognizes
this
by the fact that they also define a simple Date-only format (Namely
"Date")
as an alternative to DateTime.

I wish Microsoft would have given us some kind of property to set to
control
whether dates are spit out as DateTime or Date rather than forcing
DateTime.
In our particular application, we need to send to customers around the
world, lists of dates indicating when bank holidays occur around the
world.
It doesn't make sense to have my particular time zone information (Eastern Standard) included in a list of bank holidays for Tokyo.

The problem with your suggestion for my particular case is that I also
want
to be able to use the ds.WriteXmlSche ma method to send my clients a
schema
which matches my data. So I would also have to do some fiddling with that to match the changes you've suggested. I suppose I could just create a
new
string field in my Datatable to contain the string value of the date, but then the schema would define that field as a String rather that a Date.
Perhaps your suggestion is my only option and I'll have to also have code to
modify the schema and code to make sure everything is in synch - yecht.

I hope I don't sound like I'm complaining to you. I just hope someone
from
Microsoft is watching.

Thanks again for your help.
Bob Scarborough
"Derek Harmon" <lo*******@msn. com> wrote in message
news:uj******** ******@TK2MSFTN GP15.phx.gbl...
"Robert Scarborough" <r0************ ******@hotmail. com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
> I have a Table in a Typed Dataset which contains a Date field called
> EventDate. I've ensured that the field is defined as Date as opposed
> to DateTime in the Typed Dataset.
: :
> <EventDate>20 04-01-26T00:00:00.000 0000-05:00</EventDate>
>
> which is the DateTime datatype of the W3C XML Schema Part 2:
Datatypes >
> I want the dates to come out as
>
> <EventDate>20 04-01-26</EventDate>

I think you'll need to use an XmlTextWriter subclass to intercept the

output
of WriteXml( ) when it's writing these dates. Here's a XmlTextWriter

to get
you started,

- - - DsDateFilterXml TextWriter.cs
// . . .
public class DsDateFilterXml TextWriter : XmlTextWriter
{
private string watchElement;
private bool onWatch;

public DsDateFilterXml TextWriter( TextWriter writer, string

watchElement) : base( writer)
{
this.watchEleme nt = watchElement;
}

public override void WriteStartEleme nt( string prefix, string

localName, string ns)
{
base.WriteStart Element( prefix, localName, ns);
if ( 0 == string.Compare( this.watchEleme nt, localName))
{
onWatch = true;
}
}

public override void WriteString( string text)
{
if ( onWatch )
{
try
{
DateTime dt = DateTime.Parse( text);
text = dt.ToString( "yyyy-MM-dd");
}
catch ( FormatException )
{
;
}
onWatch = false;
}
base.WriteStrin g( text);
}
}
// . . .
dataSet1.WriteX ml( new DsDateFilterXml TextWriter( Console.Out,

"EventDate" ) );
// . . .
- - -

The DataSet represents the value with the time zone to ensure it's

unambiguous
what date it represents (for instance, at 11 p.m. in Chicago, the date

you've
given is January 25, but in London, England, it's January 26).
Derek Harmon



Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
350
by: Robert Scarborough | last post by:
I have a Table in a Typed Dataset which contains a Date field called EventDate. I've ensured that the field is defined as Date as opposed to DateTime in the Typed Dataset. When I generate an xml file from an instance of this typed dataset using the ds.WriteXml method, all the dates come out formatted as follows: <EventDate>2004-01-26T00:00:00.0000000-05:00</EventDate>
8
43954
by: Abhijit | last post by:
hello everybody, I got a prob. I see a lot of date formats when I do a search in Google. But can any one give me some pointers / an example to extract today's date in C++ ? (formate of date: dd/mm/yyyy) Thanks in advance
9
12950
by: Alok yadav | last post by:
i am using a webservice in which a method is serach. i use this method which accept a argument of date type in dd/MM/yyyy formate. i have a textbox which accept the date from the user, when i convert textbox data into Datatime formate it converted into MM/dd/yyyy formate, but i have a requirement in dd/MM/yyyy formate. please help me, i am using c#.
3
1999
by: raahat | last post by:
hi, i need to do desperately the way of storing american DATE formate( like 27-02-2007) in mysql table.i searched on the web a lot,but didnt find anything.PLZ i need someone's help.
1
3860
by: Gurunath | last post by:
Hello All, In database i am storing value in "2007-03-22 02:00:00-05" formate And from input i am taking start date in "2007-3-25" formate and end date in "2007-5-20" formate . Now what i want is i want to fetch all the records from the table which comes between this start and end date. Can anyone help me with this. Thank you Gurunath
2
6142
by: remya1000 | last post by:
How to convert UTC formate time to local time.using vb.net. In my application in some point of the execution i need to retrieve a date,but instead of date i get some numbers,for example "200706062000". and it means 2007 June 06 20:00. How to convert these numbers to a date,more specifically to local time? in this format "#06/06/2007 08:00 PM#" if you have any idea please let me know. if example is there that will be great helpful to...
6
2404
by: Steve Ryan | last post by:
can anyone send me to some good examples of edit in place for data frid columns i see dot net let me assign a control in the IDE any good sources of reading on editing columns with controls and setting styles thanks
2
2367
by: Stevienashaa | last post by:
Hello I'm using Access 2003, and I have a query (written in SQL) which has two parameters and asks the user for two dates. This has been working fine. Today I modified the query, removing the paramerters and hard- coding some dates in, in dd/mm/yy format. To my surprise I got a different number of records returned. I then, as an experiment, change the date format to dd/mm/yyyy. This again returned a different number of records,...
2
2089
by: kkshansid | last post by:
i want to know how to change date formate in visual basic project from control panel???? from mm/dd/yyyy to dd/mm/yyyy in vb calender control
0
1314
by: kkshansid | last post by:
i know about formate function but i want to confirm that if it has anything to do with system date time in controll panel such that dd/mm/yyyy when i formate system it changes to mm/dd/yyyy pattern i only want to confirm can it be true
0
9751
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11024
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10679
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10752
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10370
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9513
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7914
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5741
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4154
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.