I am working on a project to evaluate the difference between dates. I am designing a macro to do this but it is proving to be difficult. I will post my code when I am done.
If anyone has done this I would appreciate the help.
01/15/2003 - 12/31/2002 = 15
Thanks
Eric Dye
Number of Days Between Dates
Moderators: JRL, Dorian (MJT support)
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
The current of Macro Scheduler has VB built in. The following Macro Scheduler script calculates the difference between two dates.
=======================
VBSTART
VBEND
Let>Date1=01/15/2003
Let>Date2=12/31/2002
VbEval>DateDiff("d","%Date2%","%Date1%"),Span
Message>Difference is %Span% days.
================================
To do this without DateDiff, you will have to break the dates into years, months, days, calculate the differences between each interval, and add the totals. This will require a number of If> statements to allow for 28,30 and 31 day months. You could use 28 as a basis and then add 2 or 3 based on the actual month.
You could do a number of steps:
1. First parse the date into numbers for days, months, years.
2. How many days till end of oldest month?
3. How many days into the newest month? Add to #2.
4. How many months in between oldest and newest month? Add 28 to #3 for each month.
5. How many of those months have 30 days?. Add 2 to #4 for each 30 day month.
6. How many of those months have 31 days?. Add 3 to #5 for each 31 day month.
7. Do similar routine for years, how many years between oldest year and newest year? Add 365 to #6 for every year and add 1 more for each leap year.
Is it doable? yes......
Is it worthwhile? Happy programming, I will use the built in VB.
Enjoy
=======================
VBSTART
VBEND
Let>Date1=01/15/2003
Let>Date2=12/31/2002
VbEval>DateDiff("d","%Date2%","%Date1%"),Span
Message>Difference is %Span% days.
================================
To do this without DateDiff, you will have to break the dates into years, months, days, calculate the differences between each interval, and add the totals. This will require a number of If> statements to allow for 28,30 and 31 day months. You could use 28 as a basis and then add 2 or 3 based on the actual month.
You could do a number of steps:
1. First parse the date into numbers for days, months, years.
2. How many days till end of oldest month?
3. How many days into the newest month? Add to #2.
4. How many months in between oldest and newest month? Add 28 to #3 for each month.
5. How many of those months have 30 days?. Add 2 to #4 for each 30 day month.
6. How many of those months have 31 days?. Add 3 to #5 for each 31 day month.
7. Do similar routine for years, how many years between oldest year and newest year? Add 365 to #6 for every year and add 1 more for each leap year.
Is it doable? yes......
Is it worthwhile? Happy programming, I will use the built in VB.
Enjoy
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
I made a slight change to the calculation line to give you the absolute value of days, making it unnecessary to worry about the sequence. You will always get a positive value.
Changes are in bold
VbEval>Abs(DateDiff("d","%Date2%","%Date1%")),Span
Changes are in bold
VbEval>Abs(DateDiff("d","%Date2%","%Date1%")),Span
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
Bob,
Thanks for the VB Script I will probably go that route but...
I also figured out another way to do the date differnce in days inside of Macro Scheduler. There is a bunch of code in the example but it is not all used to figure out the difference, still more than VBscript but not as bad as you thought.
The Sub and Add functions can handle dates and they work quite well. The meat of this operation is:
Get your 2 dates (one being today and the other is your date to compare)
Check to see if they are equal
if not deduct 1 day from todays date and check equality again
count the number of times you have to loop through until the dates are equal. That is the difference in Days
Thanks Again,
Eric Dye
Begin Script Example
Let>MaxDaysOld=13
GetFileList>%FidelityPath%*.*,FidFiles
Separate>FidFiles,;,file_names
MessageModal>Num Files: %file_names_count%
Let>k=0
Repeat>k
Let>k=k+1
FileDate>file_names_%k%,Fid_File_Date
MidStr>%Fid_File_Date%,1,4,File_Year
MidStr>%Fid_File_Date%,5,2,File_Mo
MidStr>%Fid_File_Date%,7,2,File_Day
Concat>File_Mo,/
Concat>File_Day,/
Concat>File_Mo,%File_Day%
Concat>File_Mo,%File_Year%
Let>Final_File_Date=%File_Mo%
Let>Diff=0
GetDate>Today
Label>FindDiff
If>%Final_File_Date%=%Today%,Diff_Is,Diff_Chk
Label>Diff_Is
If>%Diff%>%MaxDaysOld%,DelFile,DoneDiff
Label>Diff_Chk
'messagemodal>%Diff%
MessageModal>%Today%
'MessageModal>%Final_File_Date%
Sub>%Today%,1
Add>Diff,1
Goto>FindDiff
Label>DelFile
DeleteFile>file_names_%k%
Label>DoneDiff
MessageModal>Final Difference was %Diff%
Until>k,file_names_count
Thanks for the VB Script I will probably go that route but...
I also figured out another way to do the date differnce in days inside of Macro Scheduler. There is a bunch of code in the example but it is not all used to figure out the difference, still more than VBscript but not as bad as you thought.
The Sub and Add functions can handle dates and they work quite well. The meat of this operation is:
Get your 2 dates (one being today and the other is your date to compare)
Check to see if they are equal
if not deduct 1 day from todays date and check equality again
count the number of times you have to loop through until the dates are equal. That is the difference in Days
Thanks Again,
Eric Dye
Begin Script Example
Let>MaxDaysOld=13
GetFileList>%FidelityPath%*.*,FidFiles
Separate>FidFiles,;,file_names
MessageModal>Num Files: %file_names_count%
Let>k=0
Repeat>k
Let>k=k+1
FileDate>file_names_%k%,Fid_File_Date
MidStr>%Fid_File_Date%,1,4,File_Year
MidStr>%Fid_File_Date%,5,2,File_Mo
MidStr>%Fid_File_Date%,7,2,File_Day
Concat>File_Mo,/
Concat>File_Day,/
Concat>File_Mo,%File_Day%
Concat>File_Mo,%File_Year%
Let>Final_File_Date=%File_Mo%
Let>Diff=0
GetDate>Today
Label>FindDiff
If>%Final_File_Date%=%Today%,Diff_Is,Diff_Chk
Label>Diff_Is
If>%Diff%>%MaxDaysOld%,DelFile,DoneDiff
Label>Diff_Chk
'messagemodal>%Diff%
MessageModal>%Today%
'MessageModal>%Final_File_Date%
Sub>%Today%,1
Add>Diff,1
Goto>FindDiff
Label>DelFile
DeleteFile>file_names_%k%
Label>DoneDiff
MessageModal>Final Difference was %Diff%
Until>k,file_names_count