-1

I have this string value

var d = "2016-01-07 09"

It's a string that contains a date with hour without minutes, seconds and millis. I want to trasform into Datetime with this format

2016-01-07 09:00:00:000

I know that it sounds stupid but this stuff makes me crazy. Thanks for support.

MetalMad
  • 416
  • 5
  • 19
  • 4
    Did you try searching, and perhaps come along [`DateTime.TryParseExact()`](https://msdn.microsoft.com/en-us/library/ms131044(v=vs.110).aspx)? Or did you do that, and are you having trouble converting the `DateTime` to a string in this specific format? Please read [ask] and show what you have tried. – CodeCaster Jan 08 '16 at 23:16
  • 1
    And while there are better ways, `+ ":00:00:000"` is also a solution. – H H Jan 08 '16 at 23:18
  • There are so many duplicates of this question, suggest you improve your Google fu. – Jeremy Thompson Jan 08 '16 at 23:18
  • 2
    Check this link: http://stackoverflow.com/questions/15738608/converting-dd-mm-yyyy-formatted-string-to-datetime – Dobromir Nikolov Jan 08 '16 at 23:18
  • Is that date supposed to be Jan. 7th or July 1st? It could be parsed either way you do realize, right? – JB King Jan 08 '16 at 23:29
  • 1
    @JBKing - the whole purpose for year-in-front is to solve that issue. Anyone formatting a July date this way should not be allowed near a computer. – H H Jan 08 '16 at 23:38

1 Answers1

1

You have a Date with format Year - Month - Day Hour (yyyy-MM-dd HH).

You can use DateTime ParseExact method . If you know your dates format. You can parse it .

Check dateformats on this link

 string d= "2016-01-08 03";
 var c = DateTime.ParseExact(d, "yyyy-MM-dd HH", CultureInfo.InvariantCulture);
return c;
halit
  • 1,128
  • 1
  • 11
  • 27