Reputation: 97
I need to remove the Time from the date-time format.
My current output:
<Members>
<Member>
<EmployeeName>Dorothy Yan</EmployeeName>
<DateofBirth>05-30-2016T00:00:00+05:30</DateofBirth>
</Member>
<Member>
<EmployeeName>Dorothy Yan</EmployeeName>
<DateofBirth>01-25-2014T00:00:00+05:30</DateofBirth>
</Member>
</Members>
I need to remove the time from DateofBirth
Correct Output
<Members>
<Member>
<EmployeeName>Dorothy Yan</EmployeeName>
<DateofBirth>05-30-2016</DateofBirth>
</Member>
<Member>
<EmployeeName>Dorothy Yan</EmployeeName>
<DateofBirth>01-25-2014</DateofBirth>
</Member>
</Members>
I'm using c# code in WEB API project. any one help me. I searched in Google but unable to find the solution.
Upvotes: 0
Views: 1587
Reputation: 1
You should post the code that create the date so we can see what type of Date data you used and how you get the ouput. I will assume you're creating the xml from c# because you tag the question with c#. But you should be able to do it with a pattern.
With tostring like that :
DateTime thisDate1 = new DateTime(2011, 6, 10);
String dateFormat = thisDate1.ToString("MM dd yyyy");
Look here : http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
in youre case the pattern would be MM-dd-yyyy like the exemple.
Upvotes: 0
Reputation: 11317
You can do it easily with a regex (without handling XElement or doing DateTime parsing):
String xmlInitialContent = .... // Content of your initial xml
Regex rgx = new Regex("T\d\d:\d\d:\d\d+\d\d:\d\d");
String result = rgx.Replace(xmlInitialContent, String.Empty) ;
Upvotes: 1