Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I store date data in sqlserver as datatype datetime.
so i want to display date in webpage like this: 31 May 2011.

please help me how can i do this.
Thanks in advance

any one can tell me first how to store data from table in a variable then i want to convert like this:
i use store data like this

string myDate = dr["article_date"].ToString();

then how can i display myDate like 31 May 2011.

Please check : i use like this:
string article_date = dr["date"].ToString("dd MMM yyyy");
but it shown error
Posted
Updated 1-Jun-11 20:42pm
v3

try dis link
[^]
 
Share this answer
 
Here is how to do it

SELECT CONVERT(VARCHAR(11), GETDATE(), 106) AS [DD MON YYYY]


and here is the link where you can know more about it

Click Here
 
Share this answer
 
txtDate.Text = Convert.ToString(Dt.ToString("dd MMM yyyy"));


Hope this can help you.
 
Share this answer
 
Comments
Abhijit Jana 2-Jun-11 2:30am    
Do we really required ToString() Twice ? . It can done txtDate.Text = Dt.ToString("dd MMM yyyy"); :)
DateTime dt = new DateTime();
dt.ToString("dd/MMM/yyyy") ;

In short you just need to override tostring method

If you need without slash

DateTime dt = new DateTime();
dt.ToString("dd MMM yyyy");


Here is the link of different date formats for your further need

http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8-F859AA20581F.htm[^]
 
Share this answer
 
v3
try this code..
C#
string myDate = "date from database";
            DateTime dt;

            //verify given date is valid or not
            if (DateTime.TryParseExact(myDate, "dd/MMM/yyyy", CultureInfo.InvariantCulture,     System.Globalization.DateTimeStyles.None, out dt))
            {
               //Valid date format
               MessageBox.Show(dt.ToString("dd MMM yyyy"));

            }
 
Share this answer
 
 
Share this answer
 
string dt=dr["Dat"].tostring("dd MMM yyyy");
 
Share this answer
 
Comments
rahul dev123 2-Jun-11 2:34am    
I already use this but it shown error
You can do it either SQL Server End, while retrieving the data from SQL Server or using ToString("dd MMM yyyy") with your object to get the same.
 
Share this answer
 
Comments
rahul dev123 2-Jun-11 2:38am    
Ho to use ToString, i already use like this:
string article_date = dr["date"].ToString("dd MMM yyyy");
but it shown error

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