getFormattedDate

- UPDATE -

This task was developed before such functionality was built-in to Tasker. I recommend that you use the built-in action Parse/Format DateTime instead of this task.

ORIGINAL POST:

This task is intended to be used with the Perform Task action, allowing you to provide a time (seconds) and a format string. Specific character sequences in the format string will be replaced with appropriate text based on the date provided. The Return Value Variable must be global (i.e have a capital letter somewhere in it's name) in order for the date to be returned correctly. A few examples may help explain things;

Example 1

Let's say you want to flash the current date in the format Friday, March 01, 2013. To do so you would use the following action to place the formatted date into the %Mydate variable:

Perform Task [ Name:getFormattedDate Stop:Off Priority:10 Parameter 1 (%par1):%TIMES Parameter 2 (%par2):dddd, mmmm dd, yyyy Return Value Variable:%Mydate ]

Example 2

Let's say you want to save a file with a name based on the current date, and you want the name to be the 4-digit year, followed by the 2-digit month, followed by the 2-digit day. To place this file name in the %Filename variable, you would used the following action:

Perform Task [ Name:getFormattedDate Stop:Off Priority:10 Parameter 1 (%par1):%TIMES Parameter 2 (%par2):yyyymmdd Return Value Variable:%Filename ]

Format string substitutions

Character sequences in the format string will be replaced as follows:

Character Sequence Substituted Value
yyyy 4-digit year
yy 2-digit year
mmmm full month name (i.e. January, February, etc.)
mmm 3-character month name (i.e. Jan, Feb, etc.)
mm 2-digit month number
dddd full day name (i.e. Sunday, Monday, etc.)
ddd 3-character day name (i.e. Sun, Mon, etc.)
dd 2-digit day of month
hh 2-digit hour (12 hours)
HH 2-digit hour (24 hours)
nn 2-digit minute
ss 2-digit second
a/p a or p (for before noon, and noon or later)

Proposed additions by Rob Freundlich:

h 1- or 2-digit hour (12 hours)
A/P AM or PM (for before noon, and noon or later)

Note to Uncle Mike from Rob - I have uploaded getFormattedDate.tsk(1).xml containing these changes. If the Wiki had a comments section, I'd have just put this all in there, with my code changes. What's a better way to do this sort of thing?

Edit 11/11/17: The two proposed additions aren't working in Tasker 5.0+. For those experiencing the same issue, try the file: getFormattedDate.tsk(2).xml
-jeffxt

Download

Download this Tasker Task

Enjoy

- UncleMike

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License