2

Possible Duplicate:
format date in c#

How do I convert a date into the following string format?

2011-07-25 15:45:00

Community
  • 1
  • 1
Michael Kniskern
  • 24,792
  • 68
  • 164
  • 231
  • 3
    Have you searched this site or MSDN? – BoltClock Jul 25 '11 at 22:47
  • @BoltClock - did not find anything that stood out. – Michael Kniskern Jul 25 '11 at 22:48
  • The top answer tells you everything you need to know and has a bunch of useful links. See also: http://stackoverflow.com/questions/5601160/custom-date-time-format, http://stackoverflow.com/questions/3717272/datetimeformat-issue/3717339#3717339. Also **search** the site for: http://stackoverflow.com/search?q=c%23+date+format – Kev Jul 25 '11 at 22:49
  • 1
    Do you mean "yyyy-MM-dd HH:mm:ss" - or are you asking for the method call - if so that's pretty damn lazy! – James Gaunt Jul 25 '11 at 22:49
  • Looks like you're pretty close to the right format string in your question title, +/- some capital/lowercase. – John Jul 25 '11 at 22:52
  • -1 for not knowing how to google – Moog Jul 25 '11 at 22:53
  • @James Gaunt - Not being lazy. I wanted to verify. So, do not be a jerk. – Michael Kniskern Jul 25 '11 at 22:57
  • @Merlin - I did Google it and did not find a useful resource. Figure I would ask since this has always been a helpful resource. – Michael Kniskern Jul 25 '11 at 22:59

3 Answers3

11

here is a pretty good string formatting reference. for your question, you want something like this:

MyDateTime.ToString("yyyy-MM-dd hh:mm:ss");
Muad'Dib
  • 28,542
  • 5
  • 55
  • 68
3
myDate.ToString("yyyy-MM-DD HH:mm:ss");

should do it.

Joey
  • 344,408
  • 85
  • 689
  • 683
2

You can use:

dateTime.ToString("yyyy-MM-dd HH:mm:ss");
ysrb
  • 6,693
  • 2
  • 29
  • 30