Say you have a list of dates and you want to format them into multiple separate formats.
For example, you have 2 dates:
And want to to get multiple infos about them:
- today at the current time
- yesterday at the current 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
- time
- 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
%TIMES contains the current date in seconds since January 1st, 1970
- Create a test task
- Add a Variable Set action where you set %now to %TIMES
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
- Add another Variable Set action where you set %yesterday to %TIMES - 86400 and enable the Do Maths option
STEP 2 - FORMATTING 2 DATES WITH 2 FORMATS
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.
- 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
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
- 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 |
STEP 3 - SEPARATING DATES FROM TIMES
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
- Add an AutoTools Arrays action
- Set the input to %atformatteddate()
- Enable Vertical Mode
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
- Set the Input Arrays Separator to ,
- Set the Item Separator to |
- 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
Formatting multiple dates with multiple formats at the same time
Combine AutoTools Time and Arrays actions to format multiple dates with multiple formats