C# .NET - time format conversion - Asked By spandana k on 16-Jul-11 06:02 AM

The date format is not getting coverted to mm/dd/yyyy format
pls help me.
dd = '21/07/2011';
string ggtre = DateTime.Parse(dd).ToString("MM/dd/yyyy");
 but i am getting the output as 21/07/2011.
this is the code i am using.
Riley K replied to spandana k on 16-Jul-11 06:36 AM
Try this 

string UrDate = "
System.Globalization.DateTimeFormatInfo dateInfo = new System.Globalization.DateTimeFormatInfo(); 
dateInfo.ShortDatePattern = 
DateTime validDate= Convert.ToDateTime(toDate, dateInfo); 

Try this and let me know
spandana k replied to Riley K on 16-Jul-11 06:42 AM
no it is not working..
Devil Scorpio replied to spandana k on 16-Jul-11 04:20 PM
Hi Spandana,

You can convert the date format to mm/dd/yyyy

dd - date with dd/mm/yyyy format
ggtre - date with new format mm/dd/yyyy

DateTime ggtre;
System.Globalization.CultureInfo enGB = new System.Globalization.CultureInfo("en-GB");
ggtre = Convert.ToDateTime(dd, enGB);
Radhika roy replied to spandana k on 17-Jul-11 02:34 AM
First you need to get it into a datetime object. The most common standards work via:
DateTime x = DateTime.Parse(txtDate.Text);

If you expect a freaky format, you still have to know what format it is:

DateTime x;
.TryParseExact(txtDate.Text, "YYddd", out x);

Then simply output the data:

string date = x.ToString("MM/dd/yyyy");

But you really need to enforce your formatting using regex, validators, scout's honor - something.