Change the date and time format before Json is performed?

0

I have my button that serializes my object that I use it in this way:

 private void btnJson_Click(object sender, EventArgs e)
            {
                OleDbConnection connection = MSAConnection.getConnection();
                string sql = "SELECT * FROM Persona";
                OleDbDataAdapter d = new OleDbDataAdapter(sql, connection);
                DataSet ds = new DataSet();
                d.Fill(ds,"Persona");
                string n = JsonConvert.SerializeObject(ds);
                textBox1.Text = n;
            }

everything is fine.

this is what it shows me:

{
  "Persona": [
    {
      "Id": 777,
      "nombreCompleto": "CARLOS MANUEL",
      "fecha": "2018-03-01T00:00:00",
      "hora": "1899-12-30T15:43:35"
    }
  ]
}

want to know if there is a way to serialize it like this:

{
  "Persona": [
    {
      "Id": 777,
      "nombreCompleto": "CARLOS MANUEL",
      "fecha": "2018-03-01",
      "hora": "15:43:35"
    }
  ]
}
    
asked by 01.03.2018 в 21:04
source

1 answer

0

format your data in your query:

select
      Id,
      nombreCompleto,
      Format(fecha, 'Short Date') as fecha,
      Format(hora, 'Short Time') as hora
from Persona
    
answered by 01.03.2018 / 21:35
source