Calculate time between date and now

Stuck in this date javascript.
I need to calculate days between a date value read from sql and the current dateTime
But converting the SQL date to a date string keeps bugging me i just gives Not Alloved (Na)
Works fine i a browser where I test it, any idear on how to solve it ?
Tried different date format for the new Date(), but noting works.

Script:

// Date from workflow - SQL
var apptTime = "2025-06-13 07:30:00.000" // string from SQL Query here static text.
apptTime = apptTime.substring(0,10) + " " + apptTime.substring(11,16);  //Gives 2025-06-13 07:30:00.000
Watch.Log("apptTime from SQL: " + apptTime, 3);
var apptTime = new Date(apptTime);
Watch.Log("apptTime formated: " + apptTimeNew, 3);

// current Date
var currentTime =  new Date();
Watch.Log("currentTime: " + currentTime, 3);

// Get the difference in Seconds
var differenceInSecond = (currentTime - apptTime)/1000;
Watch.Log("Difference in time: " + differenceInSecond, 3);

Workflow likes slashes instead of dashes. Try this:

// Date from workflow - SQL
var SQLTimeString = "2025-06-13 07:30:00" // string from SQL Query here static text.
var SQLDate = new Date(SQLTimeString.replace(/-/g,"/"));
Watch.log(SQLDate.getTime(),2)

var currentTime = new Date();
// Get the difference in Seconds
var diff = (currentTime - SQLDate)/1000;
Watch.Log("Difference in time: " + diff, 2);

Hello Klaus,

Looks like that there is an issue with the format of the date/time string. See the reply to the forum post Workflow Script won’t get Local Variable Value, for example.

I got the following as result

[0002] Thu Jun 12 17:30:00 PDT 2025

When executing the following line of JScript code by the Run Script task

Watch.Log(new Date("2025/06/13T07:30:00"), 2);

Thanks, pointed me in the right direction.
Just had to add this before the regex.
SQLTimeString = SQLTimeString .substring(0, SQLTimeString .length - 4);

DateTime come in with .000 in the end from SQL “2025-06-13 07:30:00.000”
Then the regex does not work.
So just removed the last 4 chars.