I am trying to calculate a date 30 days ago. This is what I am using. I put it in a message box to see the results. The results is 8/27/2021. What am I doing wrong
MsgBox Now - 30
I have also tried MsgBox DateAdd("d", -30, Now) with the same 8/27/2021 results
The full code is :
Code:
Private Sub Command177_Click()
Dim sPath As String
Dim objFSO As Object, objFolder As Object
Dim objfile As Object
'~~> Change as needed
' sPath = "C:\Users\Siddharth Rout\Desktop\Test\"
sPath = "F:\NDC Documents\NDC Access\AutoBackup\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(sPath)
For Each objfile In objFolder.Files
If Format(objfile.DateLastModified, "MM-DD-YYYY") < Format(DateAdd("d", -30, [Now])) Then
Kill objfile
End If
Next objfile
MsgBox DateAdd("d", -30, Now)
End Sub