Currently having an issue retrieving dates from mongoose. This is my schema:
var ActivitySchema = new Schema({
activityName : String
, acitivtyParticipant : String
, activityType : String
, activityDate : { type: Date, default: Date.now }
, activityPoint : Number
});
This defaults to use "mm.dd.yyyy", so all data I have which is in format "dd.mm.yyyy" defaults to Date.now.
Does anyone know if there is a "format: "dd.mm.yyyy" function which I can put directly in the Schema? Any other ideas? (would really not like to update all the data)
Thank you for any replies
As far as I know, Mongoose doesn't have a 'default format'. Instead, it saves Date
instances as (I think) RFC 822 timestamps (Mon Jan 02 2012 00:00:00 GMT+0100 (CET)
), and parses them back from the database by running new Date(INPUT)
.
That last action is your problem:
> new Date('01.02.2012')
Mon Jan 02 2012 00:00:00 GMT+0100 (CET)
As you can see, Javascript itself parses it as mm.dd.yyyy
. I don't know if that's solvable without having to update your database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With