0

How I can convert string 23:59 to datetime format? So that I can reduce the current time in it.

Example: String = 23:59 minus Datime.Now = 13.8.2014 10:59:55

Time left 12 hours 0 minutes.

2 Answers2

0

use this :

DateTime date = Convert.ToDateTime(string);
System.TimeSpan diff= DateTime.Now.Subtract(date);

diff will contain your deffernce

Youness
  • 1,468
  • 1
  • 9
  • 19
0

i would use ParseExact

TimeSpan tsDifference = DateTime.ParseExact("23:59", "HH:mm", System.Globalization.CultureInfo.InvariantCulture) - DateTime.Now;
fubo
  • 44,811
  • 17
  • 103
  • 137