格式化MySQL日期

时间:2014-05-29 17:47:45

标签: c# mysql visual-studio-2012

MySQL表包含日期格式23/11/2012,我希望显示为' 23/11'在视觉工作室的标签中,c#,怎么样?

void decorator()
{
    string myConnection = "datasource= localhost;port=3306;username=root;password=root";
    MySqlConnection myConn = new MySqlConnection(myConnection);
    MySqlCommand SelectCommand = new MySqlCommand("select * from bs.login where type='id'", myConn);
    MySqlDataReader myReader;
    myConn.Open();

    string a = string.Empty;

    myReader = SelectCommand.ExecuteReader();
    while (myReader.Read())
    a = myReader.GetString(1);

    label1.Text = a;// here i want dd/MM format but in table has dd/MM/yyyy format
}

1 个答案:

答案 0 :(得分:1)

将其转换为DateTime,然后对其进行格式化:

a = DateTime.Parse(myReader.GetString(1)).ToString("dd/MM");