Core: parse error while filtering data by created_at

Created on 18 Feb 2018  路  3Comments  路  Source: adonisjs/core

const User = use("App/Models/User");

// this is not working.. and no any example of filtering data by dates.. please help
const records = User.query().where("created_at", "<", Moment().substract(1, "day"));

// i am trying to fetch all users who were registered atleast 24 hours/ 1 day ago or before .. not today.
but it gives parse error

Most helpful comment

You need to format the moment date object as a mysql friendly string:

const yesterday = Moment().substract(1, 'day').format('YYYY-MM-DD HH:mm:ss')
const records = User.query().where('created_at', '<', yesterday)

All 3 comments

You need to format the moment date object as a mysql friendly string:

const yesterday = Moment().substract(1, 'day').format('YYYY-MM-DD HH:mm:ss')
const records = User.query().where('created_at', '<', yesterday)

Closing since @webdevian answered the question.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

douglaszaltron picture douglaszaltron  路  3Comments

seanc picture seanc  路  4Comments

dezashibi picture dezashibi  路  4Comments

milosdakic picture milosdakic  路  3Comments

ghost picture ghost  路  3Comments