Date manipulation

Hi,
I need to take today's date and manipulate it, say subtract 2 days from it. Can you please let me know how can I do that in AA?

I also want to know how can I typecast variables in AA.

Appreciate your help.

-Vatish

Comments

  • Hi,
    I would need to get last day of previous month and insert it to excel. How do I get this date in AA?
    Thanks!

  • @vatish said:
    Hi,
    I need to take today's date and manipulate it, say subtract 2 days from it. Can you please let me know how can I do that in AA?

    I also want to know how can I typecast variables in AA.

    Appreciate your help.

    -Vatish

    Hi ,
    you can use system variable to do this.
    do it like this
    $Day$/$Month$/$Year$
    This way all value return in Integer value, hence you can manipulate dates as per your requirement

    To change date you can do variable operations and store in a new custom variable.. like $Day$ - 2 , now next step is to reconstruct the date again like this

    $customvariable/$Month$/$Year$

    Rajiv

  • @rajivkumar said:

    @vatish said:
    Hi,
    I need to take today's date and manipulate it, say subtract 2 days from it. Can you please let me know how can I do that in AA?

    I also want to know how can I typecast variables in AA.

    Appreciate your help.

    -Vatish

    Hi ,
    you can use system variable to do this.
    do it like this
    $Day$/$Month$/$Year$
    This way all value return in Integer value, hence you can manipulate dates as per your requirement

    To change date you can do variable operations and store in a new custom variable.. like $Day$ - 2 , now next step is to reconstruct the date again like this

    $customvariable/$Month$/$Year$

    Rajiv

    Hi Rajiv,

    What if date is 01/01/2008, it would result to -1 if you subtract 2 on date? Will this be also applicable?

  • Use "Run Script" and create a .vbs file.
    You can't manipulate a specific date on AA unless the date is today.

  • Another way to do it is by using the AA date and time metabot:
    https://botstore.automationanywhere.com/bot/change-date-and-time-format/

    Cheers,
    Theo

  • Hi vatish & jvuorela,

    Here is the solution.
    1) For todays date please apply this code: =+TODAY() in the code.
    2) For subtract 2 days from todays date: =+TODAY()-2
    3) Last day of the previous month: =DATE(YEAR(H20),MONTH(H20),0)

    Hope you got your answers. see the AA code in screenshot attached herewith.

    Thanks,
    Sandeep Verma

    Put today's date code in H20.

  • I don't think you can give AA variables a type. When trying to use AA to format dates it would look at 2018-12 and change it to 2006 ie. do a subtraction rather than treat it as a string. So we use Run Script to run this.
    /*
    Returns yesterdays date in yyyy-mm-dd format as the web site requires.
    */
    // todays date
    var d = new Date();
    //Subtract one day
    d.setDate(d.getDate() - 1);
    //Format as yyyy-mm-dd eg 2018-01-01
    var dateString = d.getFullYear()
    + "-" + ("0" + (d.getMonth() + 1)).slice(-2)
    + "-" + ("0" + (d.getDate())).slice(-2);

    WScript.StdOut.WriteLine(dateString);
    
  • I see allot of good answers, but unfortunately not the correct one. $Date$-2 in a variable operation actually assigns the date 2 days ago to the variable. This is the only date math AA can perform

Sign In or Register to comment.