-3

Good day, I am doing an application in C# and I connect to a Mysql database. I have a column that is of type datetime and doing the select from the application also sends me the time. Only I am interested in the date.

MySqlCommand comando = new MySqlCommand();
            comando.Connection = conexion;
            comando.CommandText = "SELECT codgrupo,fecha,ciudad FROM actuacion";
            MySqlDataReader DR = comando.ExecuteReader();
            while (DR.Read())
            {
                ListViewItem ITEM = lvact.Items.Add(DR["codGrupo"].ToString());
                ITEM.SubItems.Add(DR["fecha"].ToString());
                ITEM.SubItems.Add(DR["ciudad"].ToString());
            }
            DR.Close();
            conexion.Close();
0

2 Answers 2

0

You can get the date part of a C# DateTime variable by its Date property:

var myDateOnly = myDateTime.Date;
0

Use this query:

SELECT DATE(YourDate)
FROM yourTable
6
  • Does not work, since the inquiry has more fields, I believe that I have to do when using the DataReader to filter, but not is fine as it is.
    – Tone RV
    Commented Jul 30, 2015 at 10:32
  • which column is date ?
    – Diabolus
    Commented Jul 30, 2015 at 10:35
  • fecha is the date column.
    – Tone RV
    Commented Jul 30, 2015 at 10:36
  • than, use this: SELECT codgrupo,date(fecha) as 'fecha',ciudad FROM actuacion
    – Diabolus
    Commented Jul 30, 2015 at 10:36
  • I've tried it but time keeps passing me
    – Tone RV
    Commented Jul 30, 2015 at 10:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.