Solved

How can I compare date/times in vbscript?

Posted on 2004-08-18
3
166 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
3 Comments
 
LVL 26

Accepted Solution

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

Assisted Solution

by:merowinger
merowinger earned 25 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now