c# - Comparing dates does not give me selected date -


in wpf app, i've written following code comparing selected date format.

c# code:

class harvest_base {      public static datetime storetime(string date)     {          datetime returnvalue = new datetime();          if (date == "")             return returnvalue;              //time or date component not exist             string[] formats= {"m/d/yyyy h:mm:ss tt", "m/d/yyyy h:mm tt",                 "mm/dd/yyyy hh:mm:ss", "m/d/yyyy h:mm:ss", "yyyy-mm-dd",                "m/d/yyyy hh:mm tt", "m/d/yyyy hh tt", "m/d/yyyy h:mm", "m/d/yyyy h:mm",                 "mm/dd/yyyy hh:mm", "m/dd/yyyy hh:mm",                 "h:mm tt","hh:mm tt","hh:mm:ss","h:mm","hh:mm","h:mmtt"};             datetime result;              if (datetime.tryparseexact(date, formats, system.globalization.cultureinfo.invariantculture, datetimestyles.none, out result))                 returnvalue = result;             else                 returnvalue = datetime.today;           return returnvalue;      } 

the problem here is, when set breakpoint , check 'date' object showing mw selected date properly. format of date "yyyy-mm-dd". if select "2013-08-08" returnvalue showing me date "08-01-2013 00:08:00". it's totally in different format. if ignore format, month wrong. how should solve this?

if select "2013-08-08" returnvalue showing me date "08-01-2013 00:08:00"

because mm minutes mm months therefore converting minutes.

this works well

string[] formats= {"yyyy-mm-dd"}; if (datetime.tryparseexact(date, formats, system.globalization.cultureinfo.invariantculture, datetimestyles.none, out result))     returnvalue = result; else     returnvalue = datetime.today; 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -