Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if date file is newer than actual date

Status
Not open for further replies.

DanielSand

Technical User
Nov 28, 2013
5
MX
I want to check if file date is 30 days older or newer than actual date, i mean for example if today is 29/11/2013 if my file has DateLastModified=20/10/2013 detect that file is older for 30 o more days, but also if a date was manipulated and for example has a newer date than actual date, for example:
DateLastModified=20/10/2015 in this case is newer for 30 o more days.

I have this but is only detect older files, but i couldnt find the way for detect the newer than actual date:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("c:\temp\file.txt")
Wscript.Echo "Date created: " & objFile.DateCreated
iDaysOld = 30

If objFile.DateLastModified < (Date() - iDaysOld) Then
Wscript.Echo "File is older o newer than 30 days"
End if


Thanks in advance


 
Like this ?
Code:
If objFile.DateLastModified<(Date-30) Or objFile.DateLastModified>Date Then
  Wscript.Echo "File is older than 30 days or newer than today"
End if

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank u PHV, you give me the perfect cue, even your code detect a file modified today as newer, i can take your first line and finally the code thats works is this:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("c:\temp\file.txt")

If objFile.DateLastModified<(Date-30) Or objFile.DateLastModified>(Date+30) Then
Wscript.Echo "File is older than 30 days or newer than today"
End if

Thx for ur help !!
 
Do you have some sort of time machine into the future? How can you ever have last modified newer than today + 1?

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
The porpuse of this script is to reforce a trial check in my software.i have a program, when is open for first time generate a file, this file is checked in every startup of the pc, if is older than 30 days the script make the program expire.Now to prevent the user install or open the program with a fake date, in this case clock manipulation to avoid the trial period, is for this reason the script check if the file was modified witha date newer than actual date.
 
We can obtain the Date from a web server, but, even vbs take the local clock,an user generally modify the local date set it to date in the future, then install the program trying with this, avoid the 30days trial, finally return to real date.My idea is in each startup the vbs check a file crated only the first run of my app, if vbs detects in the file a date older by 30days or newer than actual, then make an action to expire the app.
 
Almost impossible that user guess this mechanism of expiration,the vbs it will be crypted like an exe, and not only check the file date will do other neccesary task in order the main app works, the installation create 20 or more files, among them it will be the file, How we can know which is?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top