question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Store createdAt and updateAt as Unix timestamps?

See original GitHub issue

Hello. I want to propose this feature. I’ve read docs and wasn’t able to find how to do this. At my company, we store all dates as unix timestamps, which is very useful.

What do you think? I cat implement this and open a pull request.

I think we can extend timestamps to:

var thingSchema = new Schema(
  {..},
  {
    timestamps: {
      createdAt: 'created_at',
      fieldType: Number,
      dateFunc: function () {
        return Math.round(new Date().getTime()/1000); /* timestamp in seconds */
      }
    }
  }
);

where: fieldType - type of the timestamps’ fields dateFunc - custom function to create date (we store dates in seconds, but new Date().getTime() returns milliseconds)

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:5
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
vkarpov15commented, Jan 3, 2020

@SwapnilSoni1999 not currently.

1reaction
vkarpov15commented, Feb 15, 2020

@SwapnilSoni1999 yep it is released in 5.9.0, see timestamps docs for an example.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Store createAt and updatedAt as epoch unix timestamps ...
The timestamp stored in postgres is just another representation of the same information as the number of milliseconds since epoch time.
Read more >
L5.2 unix timestamp on created_at and updated_at - Laracasts
In order to use date filtering in Algolia I need to set my dates as unix ... The ´´´$table->timestamps();´´´ creates both a created_at...
Read more >
Store createAt and updatedAt as epoch unix timestamps ...
The timestamp stored in postgres is just another representation of the same information as the number of milliseconds since epoch time.
Read more >
Mongoose Timestamps - Mastering JS
Mongoose has a built-in timestamps option that sets `createdAt` and `updatedAt` on your documents automatically. Here's how you can use it.
Read more >
Mongoose Timestamps
const userSchema = new Schema({ name: String }, { timestamps: { createdAt: 'created_at', // Use `created_at` to store the created date updatedAt: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found