Formatting multiple dates with multiple formats at the same time

Combine AutoTools Time and Arrays actions to format multiple dates with multiple formats

  1. joaomgcd
    Say you have a list of dates and you want to format them into multiple separate formats.

    For example, you have 2 dates:
    • today at the current time
    • yesterday at the current time
    And want to to get multiple infos about them:
    • date
    • time
    In the end you want to have 2 arrays called date() and time() where each array contains the appropriate format for each date. For example
    • date() should contain 2016-10-19,2016-10-18
    • time() should contain 10:53:52,10:53:52 (because the 2 dates are at the same time of day)

    STEP 1 - SET TEST DATES


    • Create a test task
    • Add a Variable Set action where you set %now to %TIMES
    (i) %TIMES contains the current date in seconds since January 1st, 1970
    • Add another Variable Set action where you set %yesterday to %TIMES - 86400 and enable the Do Maths option
    (i) 86400 is the number of seconds in a day so this will set %yesterday to a date at the same time as %now minus a day


    STEP 2 - FORMATTING 2 DATES WITH 2 FORMATS


    • Add an AutoTools Time action
    • Tap Format Dates
    • Set Dates To Format to %now,%yesterday
    • Enable the Use Seconds option
    • Set Formats to yyyy-MM-dd|HH:mm:ss
    (i) Here you're separating the 2 formats you want with a | character. This can be any character or characters you want as long as it doesn't appear in the rest of the format you want to use.
    • Go back to Tasker and add a Flash action with the text %atformatteddate()
    • Run the task and check how the 2 dates appear separated by a comma and the 2 formats of each date appear separated by a |
    (i) The flash will show something like 2016-10-19|10:53:52,2016-10-18|10:53:52 where 2016-10-19|10:53:52 is the first item of the array and 2016-10-18|10:53:52 is the second one


    STEP 3 - SEPARATING DATES FROM TIMES


    • Add an AutoTools Arrays action
    • Set the input to %atformatteddate()
    • Enable Vertical Mode
    (i) Vertical Mode is used because the data is setup in a column like fashion. Non-Vertical Mode would need the data to be something like 2016-10-19|2016-10-18,10:53:52|10:53:52 instead
    • Set the Input Arrays Separator to ,
    • Set the Item Separator to |
    (i) As you can see in the data, every format is separated with a | character and every date is separated with a , character so we have to switch these around
    • In the Output section set Names to dates,times
    • Go back to Tasker and add a Flash action with the text
      • %dates()
      • %times()
    • Run the task and check how the last flash will show the dates separated into the wanted formats.



    In the end, the flash will show something like

    2016-10-19,2016-10-18

    10:53:52,10:53:52

    :cool: