1

I am about to get the substring of a list. Here is my LINQ. (Read the XML from a third-party service.)

 var Payment = from Main in xml.Descendants(ns + "OTA_AirBookRQ")
               select new
               {
                   DepartureDate = Main
                                   .Elements(ns+"Segment")
                                   .Elements(ns+"DepartureDate")
                                   .ToList(),
               }

Payment.DepartureDate[0].Value returns a date as "2012-11-14T19:05:00". All I need to get from this is "19:05:00" . How do I achieve this?

Please let me know if you need more information.

5
  • 3
    What have you tried? Commented Nov 10, 2012 at 10:39
  • @Oded Thanks for your replay. I tried like foreach(var a in Payment){a.DepatureDatetime.Findlastindex("T");} Commented Nov 10, 2012 at 10:46
  • @Oded If it is a string it possible, string polo = "Chennai(Madras)"; int index=polo.LastIndexOf("("); string mas = polo.Substring(0, index); But i dont know with List Commented Nov 10, 2012 at 10:49
  • Your question is not quite clear: What does it mean to "get a substring of a list"? Should your final result be a single time value, or another list? I.e. do you need to extract the time component for each Payment.DepartureDate[n].Value, or only for the first element? Commented Nov 10, 2012 at 10:50
  • @stakx My final result should be"19:05:00". Commented Nov 10, 2012 at 10:54

2 Answers 2

3
DateTime.Parse("2012-11-14T19:05:00").ToString("HH:mm:ss");
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot.,I tried DateTime.Parse(chk.DepartureDateTime[0].Value).ToString("HH:mm:ss"); It is working excellent., thanks again
My guess ((DateTime)chk.DepartureDateTime[0]).ToString("HH:mm:ss") should also work
0

It makes more sense to do this with the DateTime.Parse(dateString) method, but if you must use substrings, simply go: string.substring(firstPos, length); (in your case - assuming your date string is named strDate: strDate.substring(9, strDate.length-1);

Substrings: http://msdn.microsoft.com/en-us/library/system.string.substring(v=vs.100).aspx

Date Time parsing: http://msdn.microsoft.com/en-us/library/1k1skd40.aspx

1 Comment

Thanks i will check with it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.