Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,


I have string as 01/07/2011 in dd/MM/yyyy format. Now I want to change it DateTime Format .

Please help me.

Thanks

Mohd. Wasif
Posted

C#
DateTime dt = DateTime.Parse("01/07/2011");
string strdate = dt.ToString();
 
Share this answer
 
Comments
Mohd Wasif 16-Sep-11 1:55am    
Hey Dear If I have string as 13/02/2011 as in dd/MM/yyyy format.Then how I will change it in MM/dd/YYYY Format.
Mehdi Gholam 16-Sep-11 2:03am    
dt.ToString("MM/dd/yyyy");
Mohd Wasif 16-Sep-11 7:40am    
It is showing error.
Mehdi Gholam 16-Sep-11 8:10am    
What's the error?
SELECT CONVERT(VARCHAR(10), GETDATE(), 103) AS [DD/MM/YYYY]
 
Share this answer
 
C#
CultureInfo provider = CultureInfo.InvariantCulture;
DateTime dtTime = DateTime.ParseExact("01/07/2011", "dd/MM/yyyy", provider);
 
Share this answer
 
Hi,

I tried just now its working.Check below lines for to convert text to date

C#
string dt = "02/05/2011";
        DateTime dts = new DateTime(int.Parse(dt.Substring(6, 4)), int.Parse(dt.Substring(3,2)), int.Parse(dt.Substring (0,2)));
        resdiv.InnerHtml = dts.Date.ToShortDateString();


All the best
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900