0

Based on this answer I am looking for a way how to get tommorow's date and next week number to use in Tasker app, Run Shell Command.

I have tried:

date -d '+1 day' +"%Y%m%d" and similar, but still I am getting Error: 1.

In shell emulator I get bad date '+1 day'

Cannot find any android shell commands reference or man.

Some guides recommend using %TIMES variable, but not sure how.

1

I've figured it out, I had to learn to use Tasker a bit, the solution is a little awkward but it probably should be done this way in Tasker.

The most important variable for such datetime manipulations in Tasker is a global variable %TIMES which contains current time in seconds - so it is a big long integer number.

Adding e.g. 30 days to it means you need to Set variable (with Math on) like this:

%TIMES + (30 * 86400)

Tommorow is:

%TIMES + (1 * 86400)

The main problem is, that you have to convert the value to a formatted datetime string. As I understood it there is no built in command for that in Tasker.

You need to create JavaScriptlet task step for that and paste there the code from this page:

<TaskerData sr="" dvi="1" tv="4.1b1m">
    <Task sr="task54">
        <cdate>1340586441681</cdate>
        <edate>1369445351826</edate>
        <id>54</id>
        <nme>getFormattedDate</nme>
        <pri>10</pri>
        <rty>2</rty>
        <Action sr="act0" ve="3">
            <code>129</code>
            <Str sr="arg0" ve="3">var gsMonthNames = new Array(
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
);

var gsDayNames = new Array(
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday'
);

var d = new Date(par[0] * 1000);
var f = par[1];

var formatteddate = f.replace(/(yyyy|yy|mmmm|mmm|mm|dddd|ddd|dd|hh|nn|ss|a\/p)/gi,
    function($1)
    {
        switch ($1)
        {
        case 'yyyy': return d.getFullYear();
        case 'yy':   return ('0' + d.getFullYear()).slice(-2);
        case 'mmmm': return gsMonthNames[d.getMonth()];
        case 'mmm':  return gsMonthNames[d.getMonth()].slice(0,3);
        case 'mm':   return ('0' + (d.getMonth() + 1)).slice(-2);
        case 'dddd': return gsDayNames[d.getDay()];
        case 'ddd':  return gsDayNames[d.getDay()].slice(0,3);
        case 'dd':   return ('0' + d.getDate()).slice(-2);
        case 'hh':   return ('0' + ((h = d.getHours() % 12) ? h : 12)).slice(-2);
        case 'HH':   return ('0' + d.getHours()).slice(-2);
        case 'nn':   return ('0' + d.getMinutes()).slice(-2);
        case 'ss':   return ('0' + d.getSeconds()).slice(-2);
        case 'a/p':  return d.getHours() &lt; 12 ? 'a' : 'p';
        }
    }
);</Str>
            <Str sr="arg1" ve="3">45</Str>
            <Int sr="arg2" val="1"/>
            <Int sr="arg3" val="45"/>
        </Action>
        <Action sr="act1" ve="3">
            <code>126</code>
            <Str sr="arg0" ve="3">%formatteddate</Str>
            <Int sr="arg1" val="1"/>
        </Action>
    </Task>
</TaskerData>

before that Javascriptlet step you insert 2 steps where you set two input variables %par1 (contains datetime in seconds form previous step) and %par2 (contains yyyymmdd - date format).

The formatted date string is available then in %formatteddate variable.


As for getting the next week:

  • Run Shell date -d +"%Y" to %year
  • Run Shell date -d +"%V" to %week
  • Set variable %week to %week + 1 (Do Maths On)
  • Set variable %year to %year + 1 (Do Maths On) (If %week > 52)
  • Set variable %week to 1 (If %week > 52)
  • The yyyyww.htm of the next week can then be written as %year%week.htm
  • 52*7 = 364; a normal year has 365 days and a leap year has 366 days. Beacuse of this discrepancy, regardless of whether week 1 is taken to be the first full week or the first week with 4 days or more in the new year, occasionally there will be a week 53. – Duane Dibbley Dec 28 '17 at 20:30
1

Given a variable %mytimestamp set to an epoch timestamp you can use this in your shell action:

date -d @%mytimestamp +%Y%m%d

Note the @ before %mytimestamp


$ adb shell
$ date --version
toybox 0.7.4-android
$ date --help
usage: date [-u] [-r FILE] [-d DATE] [+DISPLAY_FORMAT] [-D SET_FORMAT] [SET]


Set/get the current date/time. With no SET shows the current date.

Default SET format is "MMDDhhmm[[CC]YY][.ss]", that's (2 digits each)
month, day, hour (0-23), and minute. Optionally century, year, and second.
Also accepts "@UNIXTIME[.FRACTION]" as seconds since midnight Jan 1 1970.

-d      Show DATE instead of current time (convert date format)
-D      +FORMAT for SET or -d (instead of MMDDhhmm[[CC]YY][.ss])
-r      Use modification time of FILE instead of current date
-u      Use UTC instead of current timezone

+FORMAT specifies display format string using strftime(3) syntax:

%% literal %             %n newline              %t tab
%S seconds (00-60)       %M minute (00-59)       %m month (01-12)
%H hour (0-23)           %I hour (01-12)         %p AM/PM
%y short year (00-99)    %Y year                 %C century
%a short weekday name    %A weekday name         %u day of week (1-7, 1=mon)
%b short month name      %B month name           %Z timezone name
%j day of year (001-366) %d day of month (01-31) %e day of month ( 1-31)
%N nanosec (output only)

%U Week of year (0-53 start sunday)   %W Week of year (0-53 start monday)
%V Week of year (1-53 start monday, week < 4 days not part of this year)

%D = "%m/%d/%y"    %r = "%I : %M : %S %p"   %T = "%H:%M:%S"   %h = "%b"
%x locale date     %X locale time           %c locale date/time
0

try this:

tomorrow=$(( date +%s + 86400 ))

date -d @$tomorrow +%Y%m%d

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.