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
    `DateTime.Parse()`/`DateTime.ParsExact()`? – knittl Aug 13 '14 at 08:05
  • This question gets asked unreasonably often. Did you at least *try* searching first? Maybe the documentation? Maybe Stack Overflow? Maybe the entire Internet? Or maybe just the Intellisense listing? – Cody Gray Aug 13 '14 at 08:14
  • I used the search, but I could not find a suitable answer. –  Aug 13 '14 at 09:23

2 Answers2

0

use this :

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

diff will contain your deffernce

Youness
  • 1,465
  • 1
  • 9
  • 19
0

i would use ParseExact

TimeSpan tsDifference = DateTime.ParseExact("23:59", "HH:mm", System.Globalization.CultureInfo.InvariantCulture) - DateTime.Now;
fubo
  • 42,334
  • 17
  • 98
  • 130