Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Having problem converting from DATETIME after selecting from gridview.

Please correct the codes below

C#
var dt = SqlCmd.Parameters["@ZESTABLISH"].Value.ToString();
txt_Establish.Text = String.Format("{0:dd, MMMM, yyyy}", dt);
Posted
Updated 14-Nov-14 22:57pm
v2
Comments
DamithSL 15-Nov-14 5:53am    
you taking value from sql command, not from gridview. your code and question description not maching.

Try something like this...
C#
DateTime_Value.ToString("dd-MMM-yyyy");


For More on DateTime to String Conversion...


Formats for DateTime.ToString() - Codeproject Article[^]

DateTime.ToString() - MSDN[^]
 
Share this answer
 
v2
First you need to convert the date from a string into a DateTime type, then you can convert it to the string representation you want.
C#
string dateString = SqlCmd.Parameters["@ZESTABLISH"].Value.ToString();
string currentFormat = "MM/dd/yyyy";    // No idea what your current format is.
DateTime dt = DateTime.ParseExact(dateString, currentFormat, null);

txt_Establish.Text = dt.ToString("dd, MMMM, yyyy");  // Or whatever format you want
 
Share this answer
 
Your dt must be dateTime

C#
DateTime dt = DateTime.Parse(System.DateTime.Now.ToString());
String dates = String.Format("{0:dd, MMM, yyyy}", dt); 


Refer this :

http://www.csharp-examples.net/string-format-datetime/[^]
 
Share this answer
 
v2
C#
var dt = SqlCmd.Parameters["@ZESTABLISH"].Value.ToString();
          txt_Establish.Text = String.Format( dt,"{dd, MMMM, yyyy}");


your format should be like following

C#
Format(Convert.ToDateTime(txtcreditsexp.Text), "dd-MMM-yyyy HH:mm")
 
Share this answer
 
v2

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