Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
What i want to do is to convert dd/mm/yyyy to mm/dd/yyyy in asp.net (using c#). for that what i have done is :
C#
var s = "dd/MM/yyyy";
        var d = s.Split('/')[1] + "/" + s.Split('/')[0] + "/" + s.Split('/')[2];


and call it like:
obj.DOB = Convert.ToDateTime(d); 

it is my BL and giving error -->
Quote:
The string was not recognized as a valid DateTime. There is a unknown word starting at index 0.
why? What is wrong.. My calendar format is dd/mm/yy.
Posted
Updated 4-Jul-13 20:35pm
v2

1 solution

try this..:)

C#
string oldstr = "03/12/2011";   
string strDate = DateTime.ParseExact(oldstr, "dd/MM/yyyy",null).ToString("MM/dd/yyyy");
 
Share this answer
 
v2
Comments
Rambo_Raja 5-Jul-13 2:43am    
hi ... writing this shows error as CultureInfo doesnot exist in current context.
Nirav Prabtani 5-Jul-13 2:46am    
try my updated solution...:)
Sushil Mate 5-Jul-13 2:46am    
using System.Globalization;

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