Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timestamp query with LocalDate #570

Open
zaehuun opened this issue Nov 16, 2021 · 1 comment
Open

timestamp query with LocalDate #570

zaehuun opened this issue Nov 16, 2021 · 1 comment
Labels

Comments

@zaehuun
Copy link

zaehuun commented Nov 16, 2021

In the database, date is saved by timestamp type.
Currently, this project runs by js-soda and TypeORM.
I want to check the date which is applied to LocalDate.now().minusDays(1) by using createQueryBuilder like right below.

async getLastVisitCount() {
    const yesterDay = LocalDate.now().minusDays(1);
    return await this.createQueryBuilder('user')
      .where('user.last_check_in = :date', {
        date: yesterDay,
      })
      .getCount();
  }

However, it occurs error when I perform.
If I print yesterDay of variable to console.log, LocalDate { _year: 2021, _month: 11, _day: 15 } is printed.
It occurs error when I form query on the right above of query, so I want to change it to timestamp type. How can I change?

@InExtremaRes
Copy link
Collaborator

Hi there. I haven't used TypeORM but have you tried converting the LocalDate to string?

where('user.last_check_in = :date', {
  date: yesterDay.toString(),
})

The .toString() will convert the date to an ISO string that should be then correctly interpreted by the DB.

Does that work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants