Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subtracting days from date

I'm struggling in vein to work out how to remove 5 days from today's date...

I have the following simple code that searches compares the result of a text file array search and then compares them to today's date. If the date within the text file is older than today then it deletes, if not it doesn't.

What i want though is to say if the date in the text file is 5 days or older then delete.

This is being used in the English date format.

    Sub KillSuccess()
    Dim enUK As New CultureInfo("en-GB")

    Dim killdate As String = DateTime.Now.ToString("d", enUK)

    For Me.lo = 0 To UBound(textcis)
        If textcis(lo).oDte < killdate Then
            File.Delete(textcis(lo).oPath & ".txt")
        End If
    Next

End Sub 

Thanks

like image 770
elmonko Avatar asked May 06 '14 14:05

elmonko


1 Answers

You can use the AddDays method; in code that would be something like this:

Dim today = DateTime.Now
Dim answer = today.AddDays(-5)

msdn.microsoft.com/en-us/library/system.datetime.adddays.aspx

Which would make your code

Sub KillSuccess()

    Dim killdate = DateTime.Now.AddDays(-5)

    For Me.lo = 0 To UBound(textcis)
        If textcis(lo).oDte < killdate Then
            File.Delete(textcis(lo).oPath & ".txt")
        End If
    Next
End Sub 
like image 137
Simon Martin Avatar answered Sep 21 '22 11:09

Simon Martin