asp.net - Date format conversion in c# -


how convert 04/09/2013 8:09:10 pm 09/04/2013 (mm-dd-yyyy). tried convert taking 09 date , 04 month.

please help

[httppost] public string getdailynote(datetime selecteddate) //selecteddate gets date 04/09/2013 8:09:10 pm {     string x = selecteddate.tostring("mm-dd-yyy", cultureinfo.invariantculture);     string daily;     datetime dt = convert.todatetime(x);     //dt gets value {09/04/2013 12:00:00 am} 09 date , 04 month     dnote.realdate =dt;     daily = _scheduler.getdailynote(dnote);     return daily; } 

it taking 09 date , 04 month

yes, because have said it, change

"mm-dd-yyy" 

to

"dd/mm/yyyy h:mm:ss tt"  datetime.parseexact("04/09/2013 8:09:10 pm","dd/mm/yyyy h:mm:ss tt", cultureinfo.invariantculture); 

demo

now, if want convert string format mm-dd-yyyy:

string result = dt.tostring("mm-dd-yyyy", cultureinfo.invariantculture); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -