Subtracting days from a date

I'm struggling to figure out how to remove 5 days from today ...

I have the following simple code that searches, compares the search result of an array of text files, and then compares them with today's date. If the date in the text file is older than today, it is deleted, if not.

I want, however, to say if the date in the text file is 5 days or older, and then delete.

It is 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

+6
source share
1 answer

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

What would your code do

 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 
+15
source

All Articles