Date Difference
Moderators: Dorian (MJT support), JRL
Date Difference
I'm working in a macro where a person enters one date in the following format: mmddyy. If the difference from today's date and the day keyed isn't greater than 19, I want a message to pop up.
For example, the first date keyed was 050491 (May 4, 1991) and today's date is 052207 (May 22, 2007), since the difference in these two dates is not greater than 19, I would like a my macro to stop at this time.
All I need help is calculating these date difference in years. thanks in advance.
For example, the first date keyed was 050491 (May 4, 1991) and today's date is 052207 (May 22, 2007), since the difference in these two dates is not greater than 19, I would like a my macro to stop at this time.
All I need help is calculating these date difference in years. thanks in advance.
time to think about learning a bit of VBScript.
DateDiff(interval, date1, date2 [,firstdayofweek[, firstweekofyear]])
http://msdn.microsoft.com/library/defau ... 58c8fa.asp
I would "trust" vbscript to handle this type function. There will be all manner of suggestions for writing "creative" MacroScript code (which I do as well) but when VBScript fits something this nicely, it is best to use it.
DateDiff(interval, date1, date2 [,firstdayofweek[, firstweekofyear]])
http://msdn.microsoft.com/library/defau ... 58c8fa.asp
I would "trust" vbscript to handle this type function. There will be all manner of suggestions for writing "creative" MacroScript code (which I do as well) but when VBScript fits something this nicely, it is best to use it.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Here you go:
Code: Select all
VBSTART
VBEND
Let>KeyedDate=050491
//Note DateSerial interprets a year value of between 00 and 99 as being 1900 to 1999
//If you want the user to supply a year after 1999 you need the format to be
//mmddyyyy not mmddyy as you have specified. This code will work whichever of those formats is used:
Length>KeyedDate,ld
MidStr>KeyedDate,5,ld,YY
MidStr>KeyedDate,1,2,MM
MidStr>KeyedDate,3,2,DD
VBEVal>DateDiff("yyyy",DateSerial(%YY%,%MM%,%DD%),now),yDif
If>yDif<20
MessageModal>Date entered %yDif% years ago
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Hi Marcus,
I can't find DateDiff function from index searching on my macroscheduler. So I was trying to use your VB code but macroscheduler gives me this error message. "Invalid procedure call or argument: 'DateDiff'". Could you please advise what I can do about it or is there any other way to do it?
I can't find DateDiff function from index searching on my macroscheduler. So I was trying to use your VB code but macroscheduler gives me this error message. "Invalid procedure call or argument: 'DateDiff'". Could you please advise what I can do about it or is there any other way to do it?
In 2007 when this thread started there was only VBScript for datediff. But starting with version 13 ther is a built in datedaff function. See the on-line help for more information.
Here is the above script with some mods. What do you see in the message boxes?
Code: Select all
VBSTART
VBEND
Let>KeyedDate=050491
//Note DateSerial interprets a year value of between 00 and 99 as being 1900 to 1999
//If you want the user to supply a year after 1999 you need the format to be
//mmddyyyy not mmddyy as you have specified. This code will work whichever of those formats is used:
Length>KeyedDate,ld
MidStr>KeyedDate,5,ld,YY
MidStr>KeyedDate,1,2,MM
MidStr>KeyedDate,3,2,DD
VBEval>DateSerial(%YY%,%MM%,%DD%),res
VBEvaL>now,res2
MDL>%res% %res2%
VBEVal>DateDiff("yyyy",DateSerial(%YY%,%MM%,%DD%),now),yDif
MDL>ydif
If>yDif<20
MessageModal>Date entered %yDif% years ago
Endif
Code: Select all
day>DD
month>MM
year>YYYY
VBSTART
VBEND
GetFileList>C:\Temp\google_*.txt.pgp,files
Separate>files,;,file_names
let>k=0
let>fdate_0=0
Repeat>k
let>k=k+1
let>file=file_names_%k%
Separate>file_names_%k%,\,check_file
let>filename=check_file_3
FileDate>%file%,fdate
MidStr>fdate,1,4,y1
MidStr>fdate,5,2,m1
MidStr>fdate,7,2,d1
VBEVal>DateSerial(%y1%,%m1%,%d1%),res
VBEVal>now,res2
MDL>%res%,%res2%
VBEVal>DateDiff("dd",res,now),Ddif
MDL>%Ddif%
if>DDif>15
goto>email
endif
Until>k,file_names_count
Label>email
writeln>Y:\Text\Prod_Info.txt,res,subj:*********google file is not created on %YYYY%%MM%%DD%
Label>done
[quote]
What I'm trying to do is find the file whose name is starting with google and see if it's older than 15 days. If it is then I will send out an email. Unfortunately, macroscheduler 11 doesn't recognize datediff function, it still gives me the same error message. Any suggestion?[/quote]
Close
In the datediff line change the time interval parameter to a single "d" and also put percents and quotes around the "res" variable
In the datediff line change the time interval parameter to a single "d" and also put percents and quotes around the "res" variable
Code: Select all
VBEVal>DateDiff("d","%res%",now),Ddif