How to get tomorrow's date and next week's number for use in Tasker


Question

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.


Answer

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


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes