Click here to Skip to main content
15,886,780 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my database value "2012/04/24"
i have to display database value like this 12-Apr-2012 on page.
Posted
Updated 24-Apr-12 2:55am
v2

If you want to format it at the front end and not at database level then you can try:
C#
myDate.ToString("dd-MMM-yyyy"); 
 
Share this answer
 
Comments
Nathan Stiles 24-Apr-12 11:03am    
Not sure if this is true in ASP but in WinForms when you take a DateTime object and call ToShortDateString you get a culture specific format of the date that should be a format familiar to individuals of that culture.
please change the format of your string like...

date.String(Format)
In Format u can write any format which you need...
 
Share this answer
 
DateTime dt // your date

String.Format("{0: D}", dt);

Formats

String.Format("{0:t}", dt); // "4:05 PM" ShortTime
String.Format("{0: d}", dt); // "3/9/2008" ShortDate
String.Format("{0:T}", dt); // "4:05:07 PM" LongTime
String.Format("{0: d}", dt); // "Sunday, March 09, 2008" LongDate
String.Format("{0:f}", dt); // "Sunday, March 09, 2008 4:05 PM" LongDate+ShortTime
String.Format("{0:F}", dt); // "Sunday, March 09, 2008 4:05:07 PM" FullDateTime
String.Format("{0:g}", dt); // "3/9/2008 4:05 PM" ShortDate+ShortTime
String.Format("{0:G}", dt); // "3/9/2008 4:05:07 PM" ShortDate+LongTime
String.Format("{0:m}", dt); // "March 09" MonthDay
String.Format("{0:y}", dt); // "March, 2008" YearMonth
String.Format("{0:r}", dt); // "Sun, 09 Mar 2008 16:05:07 GMT" RFC1123
String.Format("{0:s}", dt); // "2008-03-09T16:05:07" SortableDateTime
String.Format("{0:u}", dt); // "2008-03-09 16:05:07Z" UniversalSortableDateTime
 
Share this answer
 
v2
Substring(Cast(FieldNAme as varchar(20)),1,11)
 
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