Forum Discussion

Luukdb's avatar
Luukdb
Contributor
4 years ago

Change the / in aqDateTime.Today to -

Hello,   For my test I need to fill in the current date. But, our system doesn't allow the current date to be with / and it needs to be - instead. Does anyone know if it is possible to change this,...
  • tphillips's avatar
    tphillips
    4 years ago

    To avoid string splitting and weird edge cases, it would be worth looking into aqConvert.DateTimeToFormatStr() 

    e.g:

     

     

     

    function reformat_date(current_datetime) {
        return aqConvert.DateTimeToFormatStr(current_datetime, "%m-%d-%Y");
    }

     

     

     

    You can find the reference for date format specifiers here.

     

    You could do this in a script, or even just use a code snippet operation.

  • hkim5's avatar
    hkim5
    4 years ago
    function reformat_date(current_datetime) {
        return aqConvert.DateTimeToFormatStr(current_datetime, "%m-%d-%Y");
    }
    
    
    function test() {
        Log.Message(reformat_date(aqDateTime.Today()));
        return reformat_date(aqDateTime.Today());
    }

    ok- this is just a scripting question, which i think would be worthwhile going over. if you run the helper function "reformat_date" it takes in one parameter, which we are calling "current_datetime". This function (reformat_date) wants to take in the input of current_datetime (which we usually get by using the built in object/method of "aqDateTime.Today()" ) and then outputs (or "returns") the same date (which is our current date) in the format that we want with the "-" separators. This is why if you try to simply run the "reformat_date" function, you get an error, since you havent inputted any date in to reformat in the first place. 

    Now the second function  above called "test", you can see that I've now added in a second line that reads 

     return reformat_date(aqDateTime.Today());

     such that as a result or running this script routine called "test" we not only log a message that reads the reformatted output of the current date (you can also observe here that the function "reformat_date" is now using the input parameter (of "aqDateTime.Today()" which holds our current date in the original format without the "-"). The second line outputs, as a result of running this "test" function, the current date in that same reformatted version with the "-" separators.

    1. drag this "test" function in (as it is currently written, this will always grab the current date, reformat it, and return that reformatted version/ while also logging it as a message). 

    2. drag in an on screen action, grab (drag and drop the blue target sign cursor thingy) the on screen element that you would like to type into.. the operation you want to use will most likely be "SetText" or "Keys" (usually the former). 

    3. when it asks you what the value of the "SetText" operation should be, you can click the 3 dots, and point it to the "Last Operation Result". In which case this is referring to the result of the script routine "test" that we ran just prior to performing this on screen action. 

    4. profit