简体   繁体   中英

Getting the difference in days, hours and minutes between current date and the date contained in the column?

I have an application with a datagridview, I bind information directly from database, i have a column named deadline of type DateTime, this column holds the deadline date.

In my C# application, I'm iterating through all rows in the datagridview and get the specific column that contain the deadline date then I update it, something like :

public void reformatDates() {
        string endDate = null;
        foreach (DataGridViewRow rw in dataGridView1.Rows)
        {
            endDate = rw.Cells[5].Value.ToString();
            rw.Cells[5].Value = getCountDown(endDate);
        }
    }

Where the function getCountDown(DateTime endDate) get the countdown in days, hours and minutes as string.

Everything is working as expected, but as I'm iterating through all rows.. What if I have a big number of rows say 5000 rows. Do i need to iterate through all of them and update each cell ?

The function I'm using to bind informations from database is Bind(string sqlquery) and I'm currently calling it like this :

      Bind("SELECT statut,title,deadline FROM taches WHERE 1");

is there someway how to get the countdown directly from database (in days, hours and minutes) I mean something like this

pseudo-code:

      Bind("SELECT statut,title,(DateNow-deadline) FROM taches WHERE 1");

Any help would be highly appreciated. Thank-you

If I understand correctly this is what you want:

Bind("SELECT statut,title,TimeDiff(sysdate(),deadline) FROM taches WHERE 1");

Full reference: https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_sysdate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM