Howdy folks,
I’m building a process in my Node server that counts each record at the end of every day and stores them in another table. I’ll use this table later to create charts, etc.
I want to ensure that it only counts the data within that particular day. So far, I have a cron that runs a function and queries the database, asking for the counts from a particular table (in the example below, I’m using the bounces table).
My question is, can I query the database table for the records added in the last 24 hours? (note: I’m storing UNIX timestamps).
JavaScript:
const job = new CronJob(
'* * * * *',
function(){
  calculateData();
},
null,
true,
'America/Los_Angeles'
);
async function calculateData(){
  const con = await mysqlConnect();
  const sql = "SELECT COUNT(*), created FROM bounces GROUP BY created";
  return new Promise((resolve, reject) => {
    con.query(sql, function (err, result) {
      con.release();
      if (err) {
        console.error("Error queying database:", err);
        reject(err);
      } else {
        result.forEach((rawDataPacket) => {
          console.log(rawDataPacket, "worked")
        });
        resolve(result);
      }
    });
  });
  console.log("hey")
}