Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using CONVERT() function
Message
 
 
To
07/02/2019 14:17:10
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
01666022
Message ID:
01666064
Views:
32
>>>>Thank you for both replies. What happens is that if the value of @TargetDate is NULL, all works.
>>>>Or if the value of @TargetDate from the XML type is American format (that works for many customers), all works.
>>>>But when I set the value in the ASP.NET application to the XML element TargetDate, I get error.
>>>>Why I do it this way is a long story. But it works for many years.
>>>>Now I need to figure where it breaks for the British date.
>>>
>>>"if the value of @TargetDate from the XML type is American format" - That is what I am saying, in the XML the format for a DateTime is fixed, regardless you are living in US or Turkey, or choose any place you like. It is like:
>>>
>>>2019-02-28T19:00:00+03:00
>>>
>>>I don't understand what does XML datetime have to do with ToShortTimeString(). Are you sure your XML is defining a DateTime type?
>>
>>How do I convert a date (in the ASP.NET) into the format you described (above).
>>For example if I get the date value, as follows:
>>
>>DateTime TargetDate = DateTime.Now;
>>
>>How do I convert it to a string of the format "2019-02-28T19:00:00+03:00"?
>
>That is the point, you don't convert that to a string. XML serializers do that for you, you don't have to do anything special but simply keep it as a DateTime rather than a string. ie:
>
>
>void Main()
>{
>  List<Product> myProducts = new List<Product> {
>     new Product { SKU="108.100.123", ListPrice=22, Price=16, CurrencyType="TRL", EffectiveFrom = DateTime.Now},
>  };
>  XNamespace ns = "urn:my-scripts";
>  XDocument doc = new XDocument( 
>      new XDeclaration("1.0","utf-8",""),
>      new XElement("Products",
>        new XAttribute(XNamespace.Xmlns+"user",ns),
>          from p in myProducts
>          select new XElement("Product",
>                    new XElement("SKU", p.SKU),
>                    new XElement("ListPrice", p.ListPrice),
>                    new XElement("Price", p.Price),
>					new XElement("CurrencyType", p.CurrencyType),
>					new XElement("EffectiveFrom", p.EffectiveFrom)
>					)
>        )           
>  );
>  
>  var xml = new StringBuilder();
>  using (XmlWriter xw = XmlWriter.Create (xml, new XmlWriterSettings { Indent = true }))
>  {
>	  doc.Save (xw);
>  }
>  string sonuc = xml.ToString();
>  Console.WriteLine (sonuc);
>}
>
>public class Product
>{
>  public string SKU { get; set; }
>  public decimal ListPrice { get; set; }
>  public decimal Price { get; set; }
>  public string CurrencyType { get; set; }
>  public DateTime? EffectiveFrom { get; set; }
>}
>
>
>
>And the output is:
>
>
><?xml version="1.0" encoding="utf-16"?>
><Products xmlns:user="urn:my-scripts">
>  <Product>
>    <SKU>108.100.123</SKU>
>    <ListPrice>22</ListPrice>
>    <Price>16</Price>
>    <CurrencyType>TRL</CurrencyType>
>    <EffectiveFrom>2019-02-07T22:13:42.27652+03:00</EffectiveFrom>
>  </Product>
></Products>
>
My code does not use the XML serializer. And I cannot change the code - now - just for this case. So, I will have to find a solution still.
Thank you.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform