-3

How can i split my string into two datetime,

string schedulemonday=10:00am - 1:00pm; 

I want to split the two time into two datetime datatype like

DateTime starttime=10:00am;
DateTime endtime=1:00pm;
Prisoner
  • 1,839
  • 2
  • 22
  • 38
bokoce
  • 1
  • 2
  • 1
    Take a look at String.Split and DateTime.Parse and/or new DateTime(year,month,day,hour,minute,second) and show us the code and a specific problem if you get stuck. – Shannon Holsinger Sep 14 '16 at 18:48
  • Why would you start with a Date/Time in a `string` ? There is no such thing as `DateTime starttime=10:00am;` Check [here](https://msdn.microsoft.com/en-us/library/system.datetime(v=vs.110).aspx) – Jim Sep 14 '16 at 20:01

1 Answers1

0

first break up the string to get the separate date strings

string schedulemonday = "10:00am - 1:00pm"; 
string[] parts = schedulemonday.Split(' ');

part[0] and part[2] should contain the start and end times, respectively

then see this post to convert a string to a datetime

Parse string to DateTime in C#

Community
  • 1
  • 1
Mark T
  • 3,464
  • 5
  • 31
  • 45