Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can I compare date/times in vbscript?

Posted on 2004-08-18
3
Medium Priority
?
174 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

783 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