LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Subtracting the day of two dates and recieving an integer answer(VB.NET) (http://www.linuxquestions.org/questions/programming-9/subtracting-the-day-of-two-dates-and-recieving-an-integer-answer-vb-net-353410/)

mrobertson 08-15-2005 07:46 AM

Subtracting the day of two dates and recieving an integer answer(VB.NET)
 
I am using the following code to populate a listbox with id numbers with dates appended to them:

Code:

Dim coilid, x As String
            x = DateTime.Today

            For q = 0 To CoilPDIRowCount - 1
            lstcoilpdi.Items.Add((PDIDataset.Tables("Table2").Rows(q).Item("ID")) + " (" + x + ")")
            lstcoilpdi.Items.Add(q)
            Next

I want to be able to create the effect that if an Id has been in the listbox for more than two days, remove it from the listbox. I am trying to find a way to to take the current date and subract from it the date that the id entered the listbox(i.e. x in this case). Does anyone know how to do this?

tekkieman 08-15-2005 01:46 PM

This should give you something to go on...

Code:

strDate1 = "August 12, 2005"
        datDate1 = DateTime.Parse(strDate1)
        datDate2 = DateTime.Today.AddDays(-2.0)

        If (DateTime.Compare(datDate1, datDate2) > 0) Then
            MsgBox("Date 1 > Date 2")
        ElseIf (DateTime.Compare(datDate1, datDate2) = 0) Then

            MsgBox("Date 2 = Date 1")

        Else
            MsgBox("Date 2 > Date 1")
        End If

You just need to parse the date from the listbox item and cast it to a DateTime type to do the DateTime.Compare.


All times are GMT -5. The time now is 12:42 PM.