How to get todays Date in a Script

var d = new Date(); will return the current DateTime. But you’ll have to use various methods to extract the parts and build the string.

Or you can load the core lib into the JS engine and access C#'s native DateTime.Now then pass a string to format the output.

function getDate()
{
    var lib = host.lib("mscorlib");
    var now = lib.System.DateTime.Now;
    
    return now.ToString('yyyy-MM-dd HH:mm:ss');
}
3 Likes