Dateformat for %DATE ?

1,248 views
Skip to first unread message

dirk hoffmann

unread,
Aug 26, 2017, 6:02:57 PM8/26/17
to Tasker
Hi,

is it possible to set the format in which %DATE is returned ?

Ideally would need DD-MM-YY but using English language I get MM-D-YY ...

Can I change this in Android 7 (Nougat) ??

Kind regards
Dirk

Duck Redbeard

unread,
Aug 27, 2017, 12:02:47 AM8/27/17
to Tasker
You can setup a task to rearrange the date elements using a variable split. I had to do this with time to get it to standard 12 hour with am/pm suffix.

I will build that conversion task and post it. Possibly tomorrow will be done.

Duck Redbeard

unread,
Aug 27, 2017, 12:15:04 AM8/27/17
to Tasker
This reformats the date and calls it %FDATE and uses slashes between values. You can make them dashes in A4.

The Flash actions are just there to show progress. They can be deleted. If this task doesn't work for you, add a short wait step between tbe steps.

If you want to use this format in other tasks, have this run at 1 minute after midnight every day and have the other tasks use %FDATE.


Date Conversion (162)
A1: Variable Set [ Name:%CONVDATE To:%DATE Recurse Variables:Off Do Maths:Off Append:Off ]
A2: Flash [ Text:%CONVDATE Long:Off ]
A3: Variable Split [ Name:%CONVDATE Splitter:- Delete Base:Off ]
A4: Variable Set [ Name:%FDATE To:%CONVDATE2/%CONVDATE1/%CONVDATE3 Recurse Variables:Off Do Maths:Off Append:Off ]
A5: Flash [ Text:%FDATE Long:Off ]

Abdullah Alahdal

unread,
Aug 27, 2017, 1:06:17 AM8/27/17
to Tasker
I would suggest using JavaScriptLet with momentjs library. Following is my task. You can identify any format.

Date Format (201)
A1: JavaScriptlet [ Code:var tdate = moment().format('DD-MM-YYYY'); Libraries:/storage/emulated/0/Tasker/Scripts/moment.js Auto Exit:On Timeout (Seconds):45 ]
A2: Flash [ Text:%tdate Long:Off ]


You can download momentjs for here: http://momentjs.com

Gilles P

unread,
Aug 27, 2017, 2:56:07 AM8/27/17
to Tasker

is it possible to set the format in which %DATE is returned ?

Ideally would need DD-MM-YY but using English language I get MM-D-YY ...

Using shell "date" command seem to be the simpler way to do this for me.

The following action:

Run Shell [
   
Command:date +"date +%d-%m-%y"
   
Store Output In:%datestring
]

Results with formatted date in %datestring variable

Refer to this page for other available formats: https://linux.die.net/man/1/date
 

Gilles P

unread,
Aug 27, 2017, 3:04:17 AM8/27/17
to Tasker
**FIX**
Should be:
Command:date +"%d-%m-%y"

instead of

Thom Little

unread,
Aug 27, 2017, 3:19:50 AM8/27/17
to Tasker
The generalized solutionI use with %TIMES is ...

Dev5 (630)
A1: Variable Set [ Name:%par1 To:%TIMES Recurse Variables:Off Do Maths:Off Append:Off ]
A2: Variable Set [ Name:%par2 To:
dd-mm-yy Recurse Variables:Off Do Maths:Off Append:Off ]
A3: Perform Task [ Name:getFormattedDate Priority:%priority Parameter 1 (%par1):%par1 Parameter 2 (%par2):%par2 Return Value Variable:%wrk Stop:Off ]
A4: Flash [ Text:%wrk Long:Off ]


getFormattedDate (189)
Run Both Together
A1: JavaScriptlet [ Code: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() < 12 ? 'a' : 'p';
        }
    }
); Libraries:45 Auto Exit:On Timeout (Seconds):45 ]
A2: Return [ Value:%formatteddate Stop:On ]

… Thom


Rich D

unread,
Aug 27, 2017, 7:49:38 AM8/27/17
to Tasker Google Groups Post


Can I change this in Android 7 (Nougat) ??

Not that I am aware.

  This goes with Googles typical mindset that they know what is best for you and your device... 

Reply all
Reply to author
Forward
0 new messages