datetime

B

BRIAN

I am tyrying to use the System.IO.File.GetCreationTime
name space to get the creation date of a file. That's no
problem.

I want to delete a file if it is older than two weeks.

For Each File1 In Directory.GetFiles("c:\Test")
If CreationDate < (System.DateTime.Now( ) - 14) Then
File.Delete(File1)
End If
Next

my error is at (system.datetime.now() - 14)

says operator '-' is not defined for datetime or integer.

Does anyone know how to subtract a number of days from a
date that is not in datetime format?

Thanks
 
A

Alex Papadimoulis

Hi Brian,

Try:
If System.DateTime.Now.Subtract(CreationDate).Days > 14

Alex Papadimoulis
 
H

Hermit Dave

Hi,
Try using DateTime class. It has methods like Add Days. try adding in -14 to
now and then compare it with CreationDate.

Chao,
Hermit Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top