function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC n12SFDC n12 

date format conversion

Hi,

I want to convert a datetime field to date field in javsscript

var date=record.LastModifiedDate;

what is the method i can use to convert it


i am currently using the below format

var date = new Date(record.LastModifiedDate);
console.log(date.toISOString().slice(0,10));


but its displaying in the below format which is wrong

Fri May 09 2014 10:30:50 GMT+0530 (India Standard Time)

i want it in below format

2014-05-09

Thanks
Anurag JainAnurag Jain
Hi,

Try this code:-

window.onload = function() {
        var dt = new Date();
        alert(dt.getFullYear() + "-" + dt.getMonth() + "-" + dt.getDate());
    }

Thanks
Anurag Jain
AshlekhAshlekh
Hi,

You can try this also.

var myDate = '{!YEAR(record.LastModifiedate)-MONTH(record.LastModifiedate)-DAY(record.LastModifiedate)}';