%DAY,%MONTH,%YEAR %HOURS,%MINUTES,%SECONDS Varibles

3,876 views
Skip to first unread message

Zohar

unread,
Mar 16, 2015, 3:05:59 AM3/16/15
to tas...@googlegroups.com
Hi
 
 
Does Tasker have these variables?
%DAY,%MONTH,%YEAR   %HOURS,%MINUTES,%SECONDS Varibles
 
 
The closest thing I could find is %DAYM, but that's it..
 
 
Thank you

Pent

unread,
Mar 16, 2015, 5:13:55 AM3/16/15
to tas...@googlegroups.com
Use the action Variable Convert action with the %TIMES variable to
get those values.

Pent

Zohar

unread,
Mar 16, 2015, 12:18:27 PM3/16/15
to tas...@googlegroups.com
OK Thank you, I will use it.
 
 
Can I recommend to add these Global Built-in Variables?
%DATE_DAY
%DATE_MONTH
%DATE_YEAR
 
%TIME_HOURS
%TIME_MINUTES
%TIME_SECONDS
 
 
Altho as you say, we can calculate it from the existing %DATE and %TIME variables,
it takes quite several actions,
and on the other hand if you add these variables, we can make our programs musch shorter and simpler..
 
 
 

Ping Flood

unread,
Mar 16, 2015, 1:15:35 PM3/16/15
to tas...@googlegroups.com
+1


Or give us an action/function to convert from %TIMES to any custom output format.

I'm currently using JavaScript to do this, but is spent so much resources for so little task...


Regards

anon ymous

unread,
Mar 21, 2015, 4:01:06 PM3/21/15
to tas...@googlegroups.com
+1 to convert time in seconds to custom format

Meanwhile, the shell command 'date' returns the following for me: Sun Mar 22 08:57:46 NZDT 2015
Does that format help anyone?

Robert Ryan

unread,
Mar 21, 2015, 10:17:49 PM3/21/15
to tas...@googlegroups.com
@Zohar - Tasker already offers at least three different ways to get these values, e.g. Java Calendar object, Javascript, and parsing the value from Variable Convert. Why add a fourth?

@anon ymous - Formatting of time and date strings is already available using Java's SimpleDateFormat class.

paulb...@gmail.com

unread,
Mar 21, 2015, 10:50:58 PM3/21/15
to tas...@googlegroups.com

But for that I'd have to learn java. Would java get me the timezone & daylight code? That's what I use that command for.

On 22/03/2015 3:18 pm, "Robert Ryan" <rbr...@gmail.com> wrote:
@Zohar -  Tasker already offers at least three different ways to get these values, e.g. Java Calendar object, Javascript, and parsing the value from Variable Convert. Why add a fourth?

@anon ymous - Formatting of time and date strings is already available using Java's SimpleDateFormat class.

--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/dDqdOgBJ7HA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.

Saad Thahim

unread,
Mar 21, 2015, 11:20:36 PM3/21/15
to tas...@googlegroups.com
How to get this with variable convert. And pent please reply to my problem about slow working of task posted in another thread.

Robert Ryan

unread,
Mar 21, 2015, 11:21:57 PM3/21/15
to tas...@googlegroups.com
I'm not sure what you mean by daylight code, but timezone info is definitely available.

Richard Finegold

unread,
Mar 22, 2015, 12:12:08 AM3/22/15
to tas...@googlegroups.com
The date command, which might be bundled with one's ROM (or, alternatively, provided by busybox), might suffice for one's needs. For example,

A1: Run Shell [ Command:date "+%Z %z" Timeout (Seconds):0 Use Root:Off Store Output In:%datefmt Store Errors In: Store Result In: ]
A2: Flash [ Text:%datefmt Long:Off ]

Note that the bundled one might not support the -d switch (a date/time other than now) and might have other limitations. The busybox version is quite flexible.

Robert Ryan

unread,
Mar 22, 2015, 2:30:32 AM3/22/15
to tas...@googlegroups.com
@Saad Thahim - As an example, to get the current month:

Month (15)
A1: Variable Set [ Name:%now To:%TIMES Do Maths:Off Append:Off ]
A2: Variable Convert [ Name:%now Function:Seconds to Long Date Time Store Result In:%date_str ]
A3: Variable Search Replace [ Variable:%date_str Search:(?<=,\s)[[:ALPHA:]]+ Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In:%month Replace Matches:Off Replace With: ]
A4: Flash [ Text:%month() Long:On ]

Robert Ryan

unread,
Mar 22, 2015, 9:36:30 AM3/22/15
to tas...@googlegroups.com
The following task gets you the various time/date fields as global variables. It is designed to be called using the Perform Task action. Set %par1 to 1 for short month/day. Set %par1 to 2 for long month/day.

Get Time (17)
A1: Variable Set [ Name:%par1 To:1 Do Maths:Off Append:Off ] If [ %par1 != 2 ]
A2: Java Function [ Return:calendar Class Or Object:Calendar Function:getInstance
{Calendar} () Param: Param: Param: Param: Param: Param: Param: ]
A3: Java Function [ Return:locale Class Or Object:Locale Function:getDefault
{Locale} () Param: Param: Param: Param: Param: Param: Param: ]
A4: Java Function [ Return:%Month Class Or Object:calendar Function:getDisplayName
{String} (int, int, Locale) Param:2 Param:%par1 Param:locale Param: Param: Param: Param: ]
A5: Java Function [ Return:%Day_Of_Week Class Or Object:calendar Function:getDisplayName
{String} (int, int, Locale) Param:7 Param:%par1 Param:locale Param: Param: Param: Param: ]
A6: Java Function [ Return:%Date Class Or Object:calendar Function:get
{int} (int) Param:5 Param: Param: Param: Param: Param: Param: ]
A7: Java Function [ Return:%Year Class Or Object:calendar Function:get
{int} (int) Param:1 Param: Param: Param: Param: Param: Param: ]
A8: Java Function [ Return:%Hour_24 Class Or Object:calendar Function:get
{int} (int) Param:11 Param: Param: Param: Param: Param: Param: ]
A9: Java Function [ Return:%Hour Class Or Object:calendar Function:get
{int} (int) Param:10 Param: Param: Param: Param: Param: Param: ]
A10: Java Function [ Return:%Minute Class Or Object:calendar Function:get
{int} (int) Param:12 Param: Param: Param: Param: Param: Param: ]
A11: Java Function [ Return:%Second Class Or Object:calendar Function:get
{int} (int) Param:13 Param: Param: Param: Param: Param: Param: ]
A12: Java Function [ Return:%Am_Pm Class Or Object:calendar Function:getDisplayName
{String} (int, int, Locale) Param:9 Param:%par1 Param:locale Param: Param: Param: Param: ]

Ping Flood

unread,
Mar 22, 2015, 8:10:38 PM3/22/15
to tas...@googlegroups.com
To contribute with the discussion, here follow the solution I use to get formatted date/time.

Run it by Perform Task action, pass your epoch time in ms (%TIMEMS) as parameter 1 and the date format as parameter 2. Date format is any code supported by SimpleDateFormat: http://developer.android.com/reference/java/text/SimpleDateFormat.html
Result will be stored in the Return Value Variable.


E.g.:
Perform Task DateFormat
%par1: 1427069107000
%par2: yyyy-mm-dd
%res: 2015-03-23



DateFormat (39)
Run Both Together
A1: Java Function [ Return:dt Class Or Object:Date Function:new
{Date} (long) Param:%par1 Param: Param: Param: Param: Param: Param: Continue Task After Error:On ] 
A2: Java Function [ Return:df Class Or Object:SimpleDateFormat Function:new
{SimpleDateFormat} (String) Param:%par2 Param: Param: Param: Param: Param: Param: Continue Task After Error:On ] 
A3: Java Function [ Return:%res Class Or Object:df Function:format
{String} (Object) Param:dt Param: Param: Param: Param: Param: Param: Continue Task After Error:On ] 
A4: Return [ Value:%res Stop:On ] 



With kind regards

Bill Stewart

unread,
Apr 3, 2018, 5:14:21 PM4/3/18
to Tasker
Excellent - created a task with the Java functions. This is the best technique I've seen. Thanks!

Bill

Dale Smith

unread,
Apr 7, 2018, 10:23:08 PM4/7/18
to Tasker

I tried to duplicate Roberts Java Functions but I'm getting run time errors.
Anyone see the problem?

Rich D

unread,
Apr 8, 2018, 9:27:44 AM4/8/18
to Tasker Google Groups Post

I tried to duplicate Roberts Java Functions but I'm getting run time errors.
Anyone see the problem?

this action is working on my 2  devices..



Screenshot_20180408-092513.png

Dale Smith

unread,
Apr 8, 2018, 10:38:57 AM4/8/18
to Tasker
Never mind I got it working. I was using copy and paste to build the actions. After fiddling around with one I found that some of the spaces weren't spaces.

Mr. Garber

unread,
Jun 1, 2019, 9:02:11 AM6/1/19
to Tasker
I have no use for javascript other than to obtain the hour variable. I don't see how it is productive in my life to spend next 2 days trying to figure out what you guys are talking about, then trying to get the code and troubleshoot. Much less 6 months learning javascript which I turn off at every chance, abhore it and Java written programs with a passion.

You guys are myopic. Just upload files we can import to get the tasker variables, like hour. Add to the tasker docs. Thus 2 million users can save 200 million hours screwing with something so unnecessary.

ktmom

unread,
Jun 2, 2019, 7:34:51 AM6/2/19
to Tasker
Just use the autotools time action

John W.

unread,
Jun 2, 2019, 9:15:30 AM6/2/19
to Tasker
I usually just bypass Tasker's date variable as the raw format is usually inadequate for my needs unless I do some reformatting. I find dates are simpler using a code>shell command like date +"%Y/%m/%d,%H:%M:%S,%s" (formatting and value parameters available by Googling "unix date format"). This gives a useable format for csv data and can be used for conditional operations via Regex patterning.

John W.

unread,
Jun 8, 2019, 3:00:06 PM6/8/19
to Tasker
This thread has set me thinking and I think I have a solid idea, not just here, but elsewhere in Tasker as well!

Can Tasker not implement arrayed native/global vars? DATE presently returns m-d-yy. Why couldn't DATE(1:4) return a numbered year, month, day-of-month, and day-of-week? Same goes for TIME (hr, min, sec, ¿TZ?)

Perhaps a TIME() array could also swallow TIMES and TIMEMS?

Similarly, why not use WIFI for the state, WIFI(1) for connection data, and WIFI(2) for scan data?

I don't think existing vars like DAYM, DAYW, TIMES, TIMEMS, and WIFII should be deleted but rather just delisted so that existing tasks will continue to function.

I think this works on many levels: less confusion for the noob, less clutter for the vet. The beginner mode toggle could even have the effect of showing/hiding the arrayed subelements in the var list.

John W.

unread,
Jun 17, 2019, 8:27:36 PM6/17/19
to Tasker
BTW, a few years ago I commenced writing a routine to return anything I wanted in any format I wanted. It prob isn't suitable for redist, but its base functionality operates with a mere two lines:


DESC ::
Date Sandbox (66)
<year yearday yearweek yearmonth monthday weekday hours minutes seconds utc tz month day ap>
A1: Run Shell [ Command:date +"%Y %0j %0U %0m %0d %0w %0H %0M %0S %z %^Z %^p %^B %^A" Timeout (Seconds):2 Use Root:Off Store Output In:%date Store Errors In: Store Result In: Continue Task After Error:On ]
A2: Variable Search Replace [ Variable:%date Search:\S+ Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In Array:%date Replace Matches:Off Replace With: ]


XML ::
Date Sandbox (66)
<year yearday yearweek yearmonth monthday weekday hours minutes seconds utc tz month day ap>
A1: Run Shell [ Command:date +"%Y %0j %0U %0m %0d %0w %0H %0M %0S %z %^Z %^p %^B %^A" Timeout (Seconds):2 Use Root:Off Store Output In:%date Store Errors In: Store Result In: Continue Task After Error:On ]
A2: Variable Search Replace [ Variable:%date Search:\S+ Ignore Case:Off Multi-Line:Off One Match Only:Off Store Matches In Array:%date Replace Matches:Off Replace With: ]


So basically this puts everything possibly into an array (except epoch sec and epoch milisec which already have tasker vars). Just access the tokens as %date(1)...%date(14)

Examples ::
%date(1)/%date(4)/%date(5) 》 2019/06/17
%date(2) 》 168
Reply all
Reply to author
Forward
0 new messages