How to invert date of a grid

1

Ihaveadatabasewithsometablesforcontrolofsalesofsoftware,andamongthesetables,Ihavethesoftwarethatcontainsthefields,beginningofthecontractandendofthecontract.ButwhenIgivetheselectinsteadofappearinglikethis'21/12/2016'theyappearlikethisonthegrid''12/21/2016''Somesolution?

privatevoidMontarLista(){conexao.ConnectionString=strconexao;cmd.CommandText="SELECT * FROM SOFTWARES";
        cmd.Connection = conexao;

        conexao.Open();
        cmd.CommandType = CommandType.Text;
        Dr = cmd.ExecuteReader();
        DtSoftwares.Clear();
        DtSoftwares.Load(Dr);
        dataGridView1.DataSource = DtSoftwares;
        conexao.Close();
        decimal soma = 0;


        foreach (DataGridViewRow dr in dataGridView1.Rows)
        {
    
asked by anonymous 11.03.2016 / 05:05

2 answers

2

You can do

string.Format("{0:dd/MM/yyyy}", DateTime.ParseExact("12/21/2016", "MM/dd/yyyy"));

You replace "21/12/2016" by your string that is the date, or if you already have the DateTime object, just put it instead of DateTime.ParseExact .

    
11.03.2016 / 06:07
1

In the current way, I only see a simple way to solve it. Format the date directly in select

cmd.CommandText = "SELECT FORMAT(INICIO, 'dd/MM/yyyy') AS INICIO, " + 
                        " OUTROS_CAMPOS FROM SOFTWARES";

This will cause the INICIO column to be formatted with the Brazilian standard.

    
11.03.2016 / 14:22