2

I would like to use manual logic inside of a Metabase question. When referencing "Past 30 days" for example, the Metabase query builder can dynamically update the question to reference the current date. When converted to a native query, however, the dates convert to hard-coded dates eg. 2017-11-30. I've seen answers elsewhere suggesting "new Date()" etc but none of these will work within Metabase's native query editor. I'm looking for something like..

...
{
  "created_at": {"$gte": "new Date()"}
},
...

though this method does not work. Thanks in advance!

tonyyin
  • 321
  • 2
  • 9

2 Answers2

1

Using new Date()

As of v0.41, it seems like Metabase would accept the new Date() syntax and insert the server's date when writing it like so:

[{
    $group: {
        _id: new Date()
    }
}]

Proof of work on Metabase v0.41

new Date() query on Metabase working

Zachary Dahan
  • 1,419
  • 16
  • 26
-3

Take "new Date()" out of quotes, you're sending in a string.

{
  "created_at": {"$gte": new Date()}
}
Nick
  • 352
  • 1
  • 7