I have 2 strings:
string d = "09/06/24";
string t = "13:35:01";
I want to take the strings and combine them to make a datetime variable:
newDT = Convert.ToDateTime(d + t);
Compiles but when it hits that line it fails..........any ideas?
I have 2 strings:
string d = "09/06/24";
string t = "13:35:01";
I want to take the strings and combine them to make a datetime variable:
newDT = Convert.ToDateTime(d + t);
Compiles but when it hits that line it fails..........any ideas?
DateTime.Parse(d + " " + t) should do it, the problem you were probably having is the lack of space inbetween the two variables, you were trying to parse:
"09/06/2413:35:01"
As you can see, this is not a valid date format.
Try this:
string d = "09/06/24";
string t = "13:35:01";
DateTime newDT = Convert.ToDateTime(d + " " + t);
If you have a specific format of date and time in the string, then consider using DateTime.TryParseExact
which allows you to specify one or more formats to use for parsing.