cancel
Showing results for 
Search instead for 
Did you mean: 

How to implement a query comparing dates/timestamp in CAP Node js

yosra_hassad0
Explorer
0 Kudos

Hello,

I am trying to run a query that contains 2 conditions in the where part. One of this condition, I am comparing two dates. Unfortunately I couldn't find a way to make it works. I hope you can help me. thanks

Here is my code :

// DATA-MODEL.cds
entity Crypto {
    key ID                 : UUID;
        ExpireIn           : Timestamp;
        Hash : String;
}
// HANDLER 1
let sCreatedDate = new Date(); 
let sId = req.data.ID.
let sExpireIn = new Date().setDate(sCreatedDate.getDate() + 30);
const updateQuery = UPDATE(Crypto, { ID: sId }).with({
           Hash: sHash,   
            ExpireIn : sExpireIn     
        });
const tx = cds.transaction(req);
const OUpdatedData = await tx.run(updateQuery);	

Here I am facing the issue when I am calling this function. The query throw an issue Error: Cannot set parameter at row: 1. Wrong input for TIMESTAMP type

// HANDLER 2
let minDate = new Date(); 
var sHash = req.data.hash
const sQuery = SELECT.from(Requests).where({ Hash: sHash, ExpireIn: { '>=': minDate } });
return Object.assign (sQuery, { then:(r,e) => this.run(sQuery).then(r,e) });

Accepted Solutions (0)

Answers (0)