Click here to Skip to main content
15,905,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I got error when insert xml(dataset) into sql server by that cannot convert this xml date format(2011-02-04T00:00:00+05:30) into dateformat of sqlxerver.

My coding:
C#
Dataset dsTemp=new DataSet();
dsTemp.Tables.Add(MyDataTable);                                         

1...//Above DateField format is 03/02/2011 12:00:00PM
C#
string xx= dsTemp.GetXml();

2....//Above DateField format is (2011-02-04T00:00:00+05:30)

How to change 2 to 1:
Please guide me...

UPDATE from OP:
I got solution temporarily. In sql server i substring first 10 letter and stored.
it is only temporarily solution . so plz any one give technical solution. for ex: how to change date format in DataSet.GetXml()
Posted
Updated 4-Feb-11 6:28am
v3

1 solution

Hi Karthikvadugan,

The getXML() changes the date format to UTC. May need to read the XML and convert the date formats before insert into the sql server. Can use the following conversion code to convert UTC format string to any other DateTime format.

string result = Convert.ToDateTime("2011-02-04T00:00:00+05:30").ToString("MM/dd/yyyy h:mm:ss tt");

If you specify the datacolumn date time mode unspecified then it won't append that +5:30 hours.

myDateColumn.DateTimeMode = System.Data.DataSetDateTime.Unspecified;

However it is better to consider the UTC offset if users from different time zone enter the data. For that need to store the data in a common time format then convert to any zone at the time of display. Can substract the +5:30 offset, so get the meridian time and store. Later may convert to IST and display. If the data input from a same timezone then just ignore the UTC offset.
 
Share this answer
 
Comments
#realJSOP 7-Feb-11 14:16pm    
Propose as answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900