Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

date format in node.JS

Tags:

I am using mysql database,in that i have a field by name request_date. The type of the field is time stamp and the data stored in this field has the format 2012-05-16 14:59:18. But when I retrieve the same data by Node.JS, the data is displayed in the browser as

Fri Jun 08 2012 15:16:50 GMT+0530 (India Standard Time) 

Why this format change is happening?

I have written this query:

SELECT biz_registration.reqid,biz_registration.request_date,biz_registration.req_status,biz_registration.annual_cost,biz_registration.rid,biz_contact.first_name,biz_contact.last_name FROM biz_registration INNER JOIN biz_contact ON biz_registration.reqid=biz_contact.reqid ORDER BY biz_registration.request_date DESC limit '+start+','+mlimit+'' 

the html code i am using is,

options +='<div class="column" style="background-color: #E1E1E1;width:         100px;">'+result.reqid+'</div>'; options +='<div class="column" style="background-color: #E1E1E1;width: 160px;">'+result.request_date+'</div>'; 
like image 655
nithin Kumar Avatar asked Jun 25 '12 10:06

nithin Kumar


People also ask

How do I get the current date in YYYY MM DD format in node JS?

The simplest way to convert your date to the yyyy-mm-dd format, is to do this: var date = new Date("Sun May 11,2014"); var dateString = new Date(date.getTime() - (date.getTimezoneOffset() * 60000 )) .toISOString() .split("T")[0];

What date format is dd mm yyyy in Javascript?

To format a date as dd/mm/yyyy:Use the getDate() , getMonth() and getFullYear() methods to get the day, month and year of the date. Add a leading zero to the day and month digits if the value is less than 10 .

What is date now () format?

The date. now() method is used to return the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC. Since now() is a static method of Date, it will always be used as Date. now().


1 Answers

I was having the same problem, this fixed my problem:

You need to 'force' your mysql connection to format it immediately, add this into your config(connection details):

host: 'localhost', user: 'root' // .... dateStrings: 'date' 

Note that in many cases

dateStrings: true 

rather than 'date'

seems to be the needed solution.

like image 155
Balkana Avatar answered Oct 09 '22 09:10

Balkana