Share via


Convert Date Time String dd/MM/yyyy To MM/dd/yyyy

Question

Wednesday, March 13, 2013 1:39 AM

Hello There,

can somebody help me with my problem?

My story goes like this,

I have a textbox for Date input which is formatted as 'dd/MM/yyyy'

but I would want to change the Date Format to 'MM/dd/yyyy' so I can query my records from the Database

Thanks.

All replies (5)

Wednesday, March 13, 2013 2:03 AM ✅Answered

var txtDate = textBox1.Text.Trim();
 var dbDate = DateTime.Parse(txtDate).ToString("MM/dd/yyyy");
//or
  var datet1 = DateTime.ParseExact(txtDate, "MM/dd/yyyy", CultureInfo.InvariantCulture);
//or
var datet2 = DateTime.ParseExact(txtDate, "MM/dd/yyyy", null);

Wednesday, March 13, 2013 2:45 AM ✅Answered

You can user DateTime.ParseExact as below,

DateTime d=DateTime.ParseExact(textbox.Text,"dd/MM/yyyy");

string s=Format(d,"MM/dd/yyyy");


Wednesday, March 13, 2013 2:57 AM ✅Answered

Have you please try dd/MMM/yyyy format for query. I think this working fine for your query.


Wednesday, March 13, 2013 1:48 AM

Hi Nusij03,

please check,

http://stackoverflow.com/questions/4977543/mvc3-razor-change-datetime-string-from-mm-dd-yyyy-120000-am-to-mm-dd-yy

http://stackoverflow.com/questions/5033902/textboxfor-mvc3-date-formatting-and-date-validation

http://stackoverflow.com/questions/133671/format-date-on-binding-asp-net-mvc

http://stackoverflow.com/questions/1961114/date-only-from-textboxfor


Wednesday, March 13, 2013 2:37 AM

Thanks for all the replies..

@aaa_78600

I tried all you gave me.. It seems error less from the compilation

but still my Query returns wrong Dates and Records

ex. I input '01/03/2013' > in format of dd/MM/yyyy so this must be read as 01/March/2013

but the records being returned by the database are records from 3rd day of January > :