How Can We Help?

Print

Compare 2 dates and/or times and trigger a bit if they are equal

 

 

Here is the script used

#include "MacroInit.h"
//#include "subFun1.c" //Example
void Macro_main(IN *p)
{
MarcoInit
//ToDo
// Structure for representing a date
typedef struct {
int minute;
int hour;
int day;
int month;
int year;
} Date;
//
// Function to compare two dates
int areDatesEqual(Date currentDate, Date targetDate) {
if ((currentDate.year == targetDate.year) &&
(currentDate.month == targetDate.month) &&
(currentDate.day == targetDate.day) &&
(currentDate.hour == targetDate.hour) &&
(currentDate.minute == targetDate.minute)) {
return 1; // true
}
return 0; // false
}
//
int minute=BCD2BIN(LocalWord[60001]); // All are in BCD format. Convert in decimal.
int hour=BCD2BIN(LocalWord[60002]);
int day=BCD2BIN(LocalWord[60003]);
int month=BCD2BIN(LocalWord[60004]);
int year=BCD2BIN(LocalWord[60005]);
//
Date currentDate = {minute, hour, day, month, year};
//
// First target dates stored from LocalWord[0]
int target1Minute = LocalWord[0];
int target1Hour = LocalWord[1];
int target1Day = LocalWord[2];
int target1Month = LocalWord[3];
int target1Year = LocalWord[4];
//
Date targetDate1 = {target1Minute, target1Hour, target1Day, target1Month, target1Year};
//
// Second target dates from LocalWord[10]
int target2Minute = LocalWord[10];
int target2Hour = LocalWord[11];
int target2Day = LocalWord[12];
int target2Month = LocalWord[13];
int target2Year = LocalWord[14];
//
Date targetDate2 = {target2Minute, target2Hour, target2Day, target2Month, target2Year};
//
LocalBit[0] = (areDatesEqual(currentDate, targetDate1)); // Set to 1 if the target date is reached or exceeded
LocalBit[1] = (areDatesEqual(currentDate, targetDate2));
}

You can download the project: AlarmOnMonitorDate