Search code examples
node.jsorientdb

Getting DateTime difference in OrientDB


I have the following Carts table schema of orientDB. All I wanted to do is to select those records where

(CurrentTime - timeStamp) >= expiration

Table Schema

I had also tried to achive my goal thorugh converting to unix timestamp and tried following queries

SELECT * FROM Carts WHERE eval("('+new Date().getTime()+' timeStamp.asLong())/1000") >= expiration

And also by following technique but when :parameter is passed in eval funtion it convert it into '?' and don't return required data.

db.query(
        'SELECT eval("'+new Date().getTime()+' - timeStamp.asLong()") as DIFF, :nowTimeStamp as NOW, timeStamp.asLong() as THEN FROM Carts ',
        {
            params: {
                nowTimeStamp: new Date().getTime()
            }
        }).then(callback);

Solution

  • Try this query:

    SELECT * FROM Carts WHERE eval("SYSDATE().asLong() / 1000 - timeStamp.asLong() / 1000") >= expiration
    

    Hope it helps.