Prashant Sharma Prashant Sharma - 3 months ago 8
Javascript Question

How to convert datetime to date in javascript?

I took a

var
in which I only want date not the full date.

var date = new Date();

Answer

use getDate and get Month method to fetch date from full date. here i attached my code with u.

var fullDate = new Date();
console.log(fullDate);

var twoDigitMonth = fullDate.getMonth() + "";
if (twoDigitMonth.length == 1) twoDigitMonth = "0" + twoDigitMonth;
var twoDigitDate = fullDate.getDate() + "";
if (twoDigitDate.length == 1) twoDigitDate = "0" + twoDigitDate;
var currentDate = twoDigitDate + "/" + twoDigitMonth + "/" + fullDate.getFullYear();
console.log(currentDate);