Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I compare date/times in vbscript?

Posted on 2004-08-18
3
Medium Priority
?
173 Views
Last Modified: 2010-05-02
I have to code something in VBScript, and I'm not all that familiar with the syntax.

Basically, I'm trying to delete any files in a directory that are older than, say, one hour.
I've found a list of the Date/Time functions, but haven't been able to create the condition I'm looking for.

I'm trying to say something like:

Dim OldDate
OldDate = 1 hour ago

   For Each File In Folder.Files                                                
            if (File.DateLastModified <= OldDate) then            
         File.delete          
            End if
      Next

How do I get the time of one hour ago?

Thanks in advance for the assist, just trying to find the right syntax for these date commands.

0
Comment
Question by:Inward_Spiral
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 26

Accepted Solution

by:
EDDYKT earned 100 total points
ID: 11831789
check with datediff
0
 
LVL 31

Assisted Solution

by:merowinger
merowinger earned 100 total points
ID: 11831938
hi,
or try this (you have do write in your if else)


Dim fso, file, temp1,temp2, timemodify,currenttime, diff

Set fso = CreateObject("Scripting.FileSystemObject")
set file = fso.GetFile ("D:\text.txt")

temp1 = file.DateLastModified
temp2 = Right(temp1,8)
timemodify = Left(temp2,2)
currenttime = Left(Time,2)

diff = timemodify - currenttime
Msgbox diff

good luck
mero
0
 

Author Comment

by:Inward_Spiral
ID: 12128449
Sorry you two, your answers were appreciated, and your points were well overdue.

Thanks!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question