c# - datetime parsing exception -


i finding taking current date (only date) in datetime datatype.

for made googling , made following code>>

datetime dtcurrdate; dtcurrdate=datetime.parseexact(datetime.now.date.toshortdatestring(),"mm/dd/yyyy",null); 

this code giving me exception :

string not recognized valid datetime. 

what mistake within it?

please me.

i believe aware of datetime.now.date property, give current date time set 00:00:00.

now why having problem in parsing:

probably because of current culture, datetime.toshortdatestring() give (for en-us culture):

displaying short date en-us culture:  //          6/1/2009 (short date string)  

and later parsing with: "mm/dd/yyyy" need single digit m , d

so code be:

dtcurrdate=datetime.parseexact(datetime.now.date.toshortdatestring(),"m/d/yyyy",null); 

it better if can store result of toshortdatestring() in string , check kind of format get, , parse accordingly.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -