How Can We Help?
Number of days between two dates
This example show how to calculate the number of days between 2 dates with a HMI macro
You can dowload the project and try: DaysBetween2Dates
The script is as follows:
#include "MacroInit.h"
void Macro_main(IN *p)
{
MarcoInit
//ToDo
int d, m, y, d2, m2, y2, x, x2, dif;
d=LocalWord[500];
m=LocalWord[501];
y=LocalWord[502];
d2=LocalWord[503];
m2=LocalWord[504];
y2=LocalWord[505];
// m+9 modulo 12
m = (m + 9);
if (m > 11)
{
m = m-12;
}
y = (y - m / 10);
x= 365*y + y/4 - y/100 + y/400 + (m*306 + 5)/10 + ( d - 1 );
// m2+9 modulo 12
m2 = (m2 + 9);
if (m2 > 11)
{
m2 = m2-12;
}
y2 = y2 - m2 / 10;
x2= 365*y2 + y2/4 - y2/100 + y2/400 + (m2*306 + 5)/10 + ( d2 - 1 );
LocalWord[506]= x2 - x;
}