Date Format Mysql

105 views
Skip to first unread message

Aaron Castillo

unread,
Mar 27, 2015, 5:42:15 PM3/27/15
to loopb...@googlegroups.com
Hi guys , im new in loopback , so im trying to develop some api from a existing mysql database, i have a issue ,i hope u could help me.

mymodel.json:
  "properties": {
   ... 
    "createdAt": {
      "type": "Date",
      "required": false,
      "length": null,
      "precision": null,
      "scale": null,
      "mysql": {
        "dataType": "datetime",
        "dataLength": null,
        "dataPrecision": null,
        "dataScale": null,
        "nullable": "Y"
      }
   ...
  }

I made a remote method to apply some logic to input data, and then create row from result , something like this:

Mymodel.remotheMethodTest = function  (input,next) {

Module.doSomething(input,function  (err,res) {
if(err) return next(err,null);
if(res){
var row            = {};
var ncreatedAt= new Date();
                                ....
row = {
       .....
createdAt : ncreatedAt
}
//console.log(row);
Mymodel.create(row,function  (err,nrow) {
console.log(nrow);
if(err) next(err,null);
return next(null,nrow);
});
}else{
return next(null,null);
}
});
}

It works fine , but when i check database i have a datetime with hours delayed , for example when i check console.log(nrow) i have :

  ..
  createdAt: Fri Mar 27 2015 16:21:27 GMT-0500 (..)
 ... 
}

and when i check in database i have : createdAt : 2015-03-27 21:21:27 , i think loopback apply isoformat to do manage date field before insert , but i need that database insert the same date like console format.

Pdt : sry about my english.


Raymond Feng

unread,
Mar 27, 2015, 6:02:47 PM3/27/15
to Aaron Castillo, loopb...@googlegroups.com
What’s your timezone in the DB? Please note `Fri Mar 27 2015 16:21:27 GMT-0500 (..)` is GMT.
Thanks,

---
Raymond Feng
Co-Founder and Architect @ StrongLoop, Inc.

StrongLoop makes it easy to develop APIs in Node, plus get DevOps capabilities like monitoring, debugging and clustering.

and when i check in database i have : createdAt : 2015-03-27 21:21:27 , i think loopback apply isoformat to do manage date field before insert .

Pdt : sry about my english.



--
You received this message because you are subscribed to the Google Groups "LoopbackJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to loopbackjs+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aaron Castillo

unread,
Mar 30, 2015, 10:56:18 AM3/30/15
to loopb...@googlegroups.com, aaron...@gmail.com
Hi Raymond , Thanks for your answer.

My database is local , so i checked with SELECT NOW() , and the time is the same as system time so i think that loopback is changing date format internally 

Aaron Castillo

unread,
Mar 30, 2015, 11:05:01 AM3/30/15
to loopb...@googlegroups.com, aaron...@gmail.com
Raymond , recently i checked this in loopback app front page:

{"started":"2015-03-30T15:03:28.336Z","uptime":1.855}

This is GMT time , so i think loopback app is in GMT timezone , how  can  i change this ? 
Reply all
Reply to author
Forward
0 new messages