4
Answers

How to split a string and convert it into a datetime ?

Photo of Abdalla Omran

Abdalla Omran

5y
1.8k
1
07/Jan/2019:06:39:02
 
after 2019 there is ":" and because of that i can't convert to the string to date time 
how could i splti only the ":" after 2019 ? 

Answers (4)

4
Photo of Amit Gupta
NA 22.9k 248.1k 5y
var dt = "07/Jan/2019:06:39:02"; var colon = dt.IndexOf(":"); var date = dt.SubString(0, colon); var time = dt.SubString(colon+1);
Accepted
0
Photo of Abdalla Omran
NA 334 34.5k 5y
@Amit Gupta : i thank you for your help .
i want to change / into - in date how could i do it ?
0
Photo of Abdalla Omran
NA 334 34.5k 5y
string test = "07/Jan/2019:06:39:02";
 
i want to convert it into a date time but i can't because the : after 2019 it gives  an exception 
System.FormatException: 'String ' was not recognized as a valid DateTime.'
 
0
Photo of Priyanka Jain
NA 9.6k 904.3k 5y
Can you post your complete string here?