Lucid: how to get current date record in adonis?

Created on 1 May 2018  路  9Comments  路  Source: adonisjs/lucid

For that i'm using below method

return await Patient.query().where('updated_at',CURDATE())with('cases').with('visits').first()

can u guide me how to get current date record

All 9 comments

Are you getting any errors with this approach?

Hi Vrik,

Thanks for reply.

Your product is awsm.

error is CURDATE is not defined

i can also use Database.raw('') bt it gives [{"catalog":"def","db":"adonis","table":"patients","orgTable":"patients","name":"name","orgName":"name","charsetNr":33,"length":765,"type":253,"flags":0,"decimals":0,"zeroFill":false,"protocol41":true},
with result.

so, what'd i do for that?

I'm expecting User.whereDate('created_at',date)

Yeah it says CURDATE because you are calling it as a Javascript in your code. Whereas it must be passed as a string to MYSQL.

return await Patient.query().where('updated_at', 'CURDATE()')

still it is not woking,
updated_at giving 2018-05-02 12:32:15 and CURDATE() giving 2018-05-02

i think lucid dont compare both

return await Patient.query().where('updated_at', 'CURDATE()').fetch()

Lucid has nothing to compare here, it鈥檚 Mysql that compares.

Also when u say it鈥檚 not working, can u be more specific on what鈥檚 not working?

by using mysql query is
SELECT * FROMpatientsWHERE DATE(updated_at) = CURDATE()

how to convert this query into adonis
or
how to perform core query in adonis and get excet mysql result

Maybe CURDATE() needs to be wrapped in .raw('CURDATE()')?

thanks for reply

Bt still its not working

Closed for housekeeping reasons.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

watzon picture watzon  路  3Comments

hectorgrecco picture hectorgrecco  路  3Comments

mtnptrsn picture mtnptrsn  路  5Comments

alexhenriquepv picture alexhenriquepv  路  3Comments

HigoRibeiro picture HigoRibeiro  路  3Comments