Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
How to use mySql function in Sequelize Typescript

I want to use Year function on date column as I want to compare year

In raw format we can write query like this
Select * from Table where YEAR(date) = 2020

How can we convert this query in sequelize-typescript

class VenueSeason  {

...


@AllowNull(false)
@Column(DataTypes.STRING(255))
name?: string;

@AllowNull(false)
@Column(DataTypes.DATE)
startDate?: Date;

@AllowNull(false)
@Column(DataTypes.DATE)
endDate?: Date;

}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

To use mysql functions in Sequelize Typescript you can simply do this:

where: {           
          // anyOtherColumn: //value,
          [Op.and]: where(fn('YEAR', col('startDate')), _year),
        }

Do import the requirements for it from sequelize at top:

import { Op, fn, col, where } from "sequelize";

I got the hint from this question for Sequelize (Javacript) Sequelize WHERE sequelize.fn(...) AND something='something' ordering issue

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!