So I have this table
CREATE TABLE `chittytransactions` (
`ChittyTransactionID` int(11) NOT NULL,
`AuctionID` int(11) NOT NULL,
`ChittyAccNo` int(11) DEFAULT NULL,
`Date` datetime DEFAULT NULL,
`Amount` double DEFAULT NULL,
`Description` varchar(50) DEFAULT NULL,
`TransRefence` varchar(50) DEFAULT NULL COMMENT 'Reference from actual Bank transaction',
`TransStatus` tinyint(1) DEFAULT NULL COMMENT 'If Transaction Pending or Cleared',
`ClearanceDate` datetime DEFAULT NULL,
`PaymentMethod` int(1) DEFAULT NULL COMMENT '0- Cash, 1- bank transfer, 2- personal credit etc'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Im creating a trigger that checks the Date
and the clearanceDate
to see if the clearanceDate
is greater than the actual date then add a late fee. I have this so far:
DROP TRIGGER IF EXISTS chitty_before_trig;
DELIMITER ;;
CREATE TRIGGER chitty_before_trig BEFORE INSERT ON chittytransactions
FOR EACH ROW
BEGIN
DECLARE `userId` INT(11);
SELECT `UserId`
INTO `userId`
FROM chittyusers
WHERE ChittyAccNo = NEW.ChittyAccNo;
IF NEW.ClearanceDate <> NEW.`Date` THEN
UPDATE `chittyusers` SET LatePaymentFee = 50 WHERE UserId = userId;
END IF;
END;;
DELIMITER;
Using the date functions how can i check if a day has gone by etc and add a calculate late payment for each day?Please anything would be great Thank you.