Solved

How can I compare date/times in vbscript?

Posted on 2004-08-18
3
172 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 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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 …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Suggested Courses
Course of the Month9 days, 12 hours left to enroll

624 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