-3

I have 3 separate strings with the following format:

01-29-2016: a date, picked from a bootstrap datepicker

1:00am start time, picked from a dropdown, format could also be e.g. 10:00pm

2:30am end time, picked from a dropdown, format could also be e.g. 11:30pm

Using the above strings I need to construct 2 DateTime properties that represent the time range, something like below:

2016-01-29 02:30:00

2016-01-29 01:00:00

I need the DateTime properties so I could update datetime database fields

0

1 Answer 1

3

You can combine both your time parts with date part respectively and use ParseExact method with MM-dd-yyyyH:mmtt format like;

var date = "01-29-2016";
var ts1 = "1:00am";
var ts2 = "2:30am";

var dt1 = DateTime.ParseExact(date + ts1, "MM-dd-yyyyH:mmtt", CultureInfo.InvariantCulture);
// 29.01.2016 01:00:00
var dt2 = DateTime.ParseExact(date + ts2, "MM-dd-yyyyH:mmtt", CultureInfo.InvariantCulture);
// 29.01.2016 02:30:00
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.