Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
C#
string date = ddlmrpratedates.SelectedItem.Text.ToString();
      DateTime dtime = Convert.ToDateTime(date);
      objFeedRetPL.date = dtime;

Here my dropdown list Date Format in "22/01/2014(MM/dd/YYYY)" format = date

I want to convert 22/01/2014 12:00:00 AM
Posted

This gives you the needed results:


C#
string time = "16:23:01";
var result = Convert.ToDateTime(time);
string test = result.ToString("hh:mm:ss tt", CultureInfo.CurrentCulture);


This gives you "04:23:01 PM"  string
 
Share this answer
 
v2
try this:

C#
string date="22/01/2014";
System.Globalization.CultureInfo Cul = new System.Globalization.CultureInfo("en-GB", true);
 DateTime d1 = DateTime.Parse(date, Cul, System.Globalization.DateTimeStyles.NoCurrentDateDefault);
 
Share this answer
 
Try this.

C#
string datestr = "22/01/2014";
      DateTime dt =  DateTime.ParseExact(datestr, "dd/MM/yyyy", null);


reference:DateTime.ParseExact[^]
 
Share this answer
 
Comments
Siva Hyderabad 22-Jan-14 8:55am    
DateTime dt = DateTime.ParseExact(datestr, "dd/MM/yyyy", null);

convertion failed exception comes here
Karthik_Mahalingam 22-Jan-14 8:57am    
post your code..
RaviRanjanKr 22-Jan-14 13:35pm    
5+
Karthik_Mahalingam 22-Jan-14 20:35pm    
THanks Ravi :)

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