How to get todays Date in a Script

Do we have a better way to get this date in a script
2024-03-18 15:45:54.000

function datetd()
{
var date= Helper.GetUniqueString();
var YYYY= Helper.GetUniqueString().substr(0,4);
var MM= Helper.GetUniqueString().substr(4,2)
var DD =Helper.GetUniqueString().substr(6,2)
var HH =Helper.GetUniqueString().substr(8,2)
var M =Helper.GetUniqueString().substr(10,2)
var SS=Helper.GetUniqueString().substr(12,2)
var FFF='000'
return date=YYYY+"-"+MM+"-"+DD+" "+HH+":"+M+":"+SS+"."+FFF;
}

We have {DATE:X}. Why do you need a script for date?

Trying to get that date in a script for a sql query

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

@memo thanks that work smoothly
return now.ToString('yyyy-MM-dd HH:mm:ss.fff');

2 Likes