Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateTime.Today.ToString("dd/mm/yyyy") returns invalid DateTime Value

Tags:

c#

datetime

I am trying to get todays date in GBR format but,

DateTime.Now.ToString("dd/mm/yyyy"); 

returns with the value of 08/00/2013

So 00 in the month group was returned instead of returning the month 04.

Any ideas why this happened?

like image 628
Farhad-Taran Avatar asked Apr 08 '13 10:04

Farhad-Taran


2 Answers

Lower mm means minutes, so

DateTime.Now.ToString("dd/MM/yyyy");   

or

DateTime.Now.ToString("d");   

or

DateTime.Now.ToShortDateString() 

works.

Standard Date and Time Format Strings

like image 169
Tim Schmelter Avatar answered Sep 18 '22 19:09

Tim Schmelter


use MM(months) instead of mm(minutes) :

DateTime.Now.ToString("dd/MM/yyyy"); 

check here for more format options.

like image 28
Arshad Avatar answered Sep 18 '22 19:09

Arshad