Date format changes when using formula

Hey everyone,

I need to generate some data to import on a mongoDB database.
There is a nice date field in mockaroo called MongoDB Iso.
And it returns the date in the format i want for example: “mongo_date”: “$date”:“2017-06-06T00:00:00.000Z”

However when i write something in the formula like “this + hours(12)”

The format changes to something default: “mongo_date”: “2017-06-06 01:00:00 UTC”,

But i want the nested $date tag with it like above. ( “mongo_date”: “$date”:“2017-06-06T00:00:00.000Z”)

The result i want:

  • “mongo_date”: “$date”:“2017-06-06T00:00:00.000Z”

The result i get:

“mongo_date”: “2017-06-06 00:00:00 UTC”

So how do i get the result i want? While still being able to use a formula on a date field.

1 Like

You need to return a Hash with key “$date”. For example:

{ "$date" => this + hours(12) }
1 Like

When I use your suggestion, I still get “$date”:“2017-06-06 12:00:00 UTC” and I need “$date”:“2017-06-06T12:00:00Z”

I also need to add 30 seconds to each new row. I tried using your suggestion but the format always changes into “$date”:“2017-06-06 12:00:00 UTC”

Yeah, there is something funny going on with date arithmetic and the mongoDB format. This formula should get the job done, though:

{ "$date" => (this.raw + hours(12)).strftime('%Y-%m-%dT%H:%M:%S.%LZ') }

To add thirty seconds to each row, add a Row Number field and do something like:

{ "$date" => (this.raw + hours(12) + (seconds(30) * row_number)).strftime('%Y-%m-%dT%H:%M:%S.%LZ') }
3 Likes