0

I have an XML file giving me the value PT0S.

 <Property name="TargetQuantity" type="double">
        <Value>PT0S</Value>
 </Property>

I have to store this value in a DATABASE table field - which is of type decimal. I have no idea how to convert this value to decimal. I am using C# to process this value. I tried to use

Convert.ToDecimal

But it does not work. Any advices would be helpful.

  • 1
    What decimal value do you want to turn "PT0S" into? Without that information, there's no possible way we can help you – canton7 Nov 30 '21 at 11:08
  • To answer your question - PT0S should be read as 0 seconds. What I understand this is a specific format. http://en.wikipedia.org/wiki/ISO_8601#Durations. This tends me to think we have to process this string. I was wondering if there is a better way to read this. – Sabyasachi Mukherjee Nov 30 '21 at 11:11

1 Answers1

4

You can't directly convert a timespan to a decimal. You need to decide which property you want.

See How do I convert an ISO8601 TimeSpan to a C# TimeSpan? (XmlConvert.ToTimeSpan(string)), and then for example save TimeSpan.TotalSeconds in your decimal column.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272