Solved

How can I compare date/times in vbscript?

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

839 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