Error with date format using sequelize and angular

0

I am developing an application in nodejs, angular and mysql. and it happens to me that when I save a date in the database with the date type and recover it with the sequelize it returns it to me in the following way "1991-04-13T00: 00: 00.000Z" and when using it in angular with the date filter {{date | date}} returns to me 1991-04-12, I've tried even with the moment js and it's returned to me in the same way. Is there any way to correct this?

    
asked by eddy_1304 01.03.2016 в 18:33
source

2 answers

0

What you can do is use a function to convert the date to UTC type, in the following way:

var fecha = new Date('1991-04-13T00:00:00.000Z'); 
var fecha_utc = new Date(fecha.getUTCFullYear(), fecha.getUTCMonth(), fecha.getUTCDate(),  fecha.getUTCHours(), fecha.getUTCMinutes(), fecha.getUTCSeconds());

In your view it would be enough to call it in the following way:

<div ng-controller="MyCtrl">
 Fecha: {{fecha | date : 'yyyy-MM-dd' }}!
</div>

Here's an example with JSFiddle link

    
answered by 01.03.2016 / 22:54
source
1

If the type of data you have put in your database is DATE and the Sequelize is returning this type of format "1991-04-13T00: 00: 00.000Z".

I was investigating the sequelize documentation, and it handles ways to return the date.

If your model is defined as DATE, sequelize returns datetime type (Take your date value from mysql eg 1991-04-13 and format it to datetime type).

If you are only going to use a date of type 1991-04-13, you would change the DATE type of your model to DATEONLY (This only returns the date)

I leave the link: link

I hope it's useful

    
answered by 03.03.2016 в 17:12