date查询MySQL

我想做一个查询,将select表中的所有行…

查询是:从dbuser中selectdate;

+------------+ | date | +------------+ | 2015-05-28 | | 2015-05-29 | | 1994-11-11 | | 2010-01-01 | | 2003-04-30 | +------------+ 

但是输出不一样:

 { date: Thu May 28 2015 00:00:00 GMT+0200 (Romance Summer Time) } { date: Fri May 29 2015 00:00:00 GMT+0200 (Romance Summer Time) } { date: Fri Nov 11 1994 00:00:00 GMT+0100 (Romance Standard Time) } { date: Fri Jan 01 2010 00:00:00 GMT+0100 (Romance Standard Time) } { date: Wed Apr 30 2003 00:00:00 GMT+0200 (Romance Summer Time) } 

我只想输出如表格YYYY-dd-mm:

 2015-05-28 2015-05-29 1994-11-11 2010-01-01 2003-04-30 

我的代码:

  app.get('/admin', function(req, res){ connection.query("select date from dbsuer", function(err, results) { if (err) throw err; console.log(results); res.send(results); }); }); 

我使用nodejs作为服务器端!

       

网上收集的解决方案 "date查询MySQL"

  app.get('/admin', function(req, res){ connection.query("select DATE_FORMAT(date,'%y/%m/%d') AS date from dbsuer", function(err, results) { if (err) throw err; console.log(results); res.send(results); }); }); 

您可以使用date_format函数强制MySQL将其转换为string,而不是让您的代码格式化date。

 SELECT DATE_FORMAT(`date`, '%Y-%m-%d') FROM dbsuer