0

How can I use datediff of postgresql with sequelizejs

this is my code

notices = await RecruitmentNotice.findAll({
      distinct: true,
      where: noticeConfig.whereQuery,
      attributes: {
        include: [
          [
            Sequelize.fn(
              'DATEDIFF',
              'year',
              Sequelize.col('RecruitmentNotice.createdAt'),
              Sequelize.col('RecruitmentNotice.endDate'),
            ),
            'datediff',
          ],
        ],
      },
    });

This code causes the following error.

 name: 'SequelizeDatabaseError',
  parent: error: function datediff(unknown, timestamp with time zone, timestamp with time zone) does not exist
hint: 'No function matches the given name and argument types. You might need to add explicit type casts.',

Please help me.

  • 1
    Well, [as documented in the manual](https://www.postgresql.org/docs/current/functions-datetime.html) there is no `datediff()` function in Postgres. What are you trying to achieve there? To get the difference between two timestamps, just subtract them, e.g. `enddate - createdat` –  Nov 06 '22 at 17:41

0 Answers0