Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dim dob As New DataColumn("dob", System.Type.GetType("System.DateTime"))

for this code, how can I formart dob Column to display like this: dd-MMM-yyyy?

any help?

Thanks in advance
Posted

You can change the default for the culture:

using System; 
using System.Globalization; 
using System.Threading;  
namespace test 
{     
  public static class Program 
  {         
    public static void Main() 
    {             
      CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
      culture.DateTimeFormat.ShortDatePattern = "dd-MMM-yyyy"; 
      culture.DateTimeFormat.LongTimePattern = "";  
      Thread.CurrentThread.CurrentCulture = culture;
      Console.WriteLine(DateTime.Now);
    }
  } 
} 
 
Share this answer
 
The format cannot be specified on the DataColumn.
It can be given to the UI control or the Report field where it is used.
For example if the Windows Forms DataGridView is used for displaying the data then the following code can be used to set the format of the Column to which the dob column of DataTable is bound.

dataGridView1.Columns["dob"].DefaultCellStyle.Format = "dd-MMM-yyyy";
 
Share this answer
 
v2
Comments
Long Bunly 26-Mar-12 12:48pm    
Thanks for reply, but the problem I use BindingSource to store this table. and I want to show it in my textbox, can u help me ?

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