Search code examples
javascriptrobotframework

How do I resolve the syntax error when using toDateString method of Javascript?


I am using Robot Framework and need to remove the time from a date. I use Get Current Date (exclude milliseconds) and pass value to a variable. The goal is to strip the time from the date. I have a syntax error which I cannot resolve.

${date}=  Get Current Date  exclude_millis=true

Execute Javascript  Date.toDateString(${date})

Error: JavascriptException: Message: javascript error: missing ) after argument list


Solution

  • The toDateString() method returns the date portion of a Date object as a human-readable string.

    Syntax:

    dateObj.toDateString();

    Parameters:

    This method does not take any parameters.

    Return value:

    A string representing the date portion of the given Date object.

    Example:

    var d = new Date();
    
    console.log(d.toDateString());
    

    Output:

    "Wed Apr 12 2017"