Komal Tope Komal Tope - 2 years ago 133
MySQL Question

How to display only date instead of datetime format from mysql to frontend javascript/jquery?

[enter image description here][1]In MySql database, the column DOB uses the data type

. But when Javascript displays the contents of that, it shows datetime format (i.e. instead of
, it displays
So please suggest solutions for this.

var xhttp = new XMLHttpRequest();

var mydata = xhttp.responseText;

mydata.forEach(function (element) {

var myTable = "" + element.DOB



following image is database table image showing correct date format


following image is frontend image showing dtae with time format."https://i.stack.imgur.com/ShZaU.png"

Answer Source
Use this code

var date = new Date("1993-02-01T18:30:00.000Z"); 
var dates = date.toDateString();
var datess = dates.split(' ');     
if(date.getMonth()+1>=10) {
return datess[2]+'-'+(date.getMonth()+1)+'-'+datess[3]+' '+date.toTimeString().split(' ')[0].slice(0,5);
} else {      
return datess[2]+'-'+'0'+(date.getMonth()+1)+'-'+datess[3]+' 
'+date.toTimeString().split(' ')[0].slice(0,5);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download