Show day of the week on Date fields

This sample code displays the day of the week next to the Date field.

Sample Image

dayoftheweek.gif

Sample Code

// Display day of the week on the Date field

(function() {
    "use strict";

    var DATE = 'due_date'; // field code of date field

    kintone.events.on(['app.record.detail.show'], function(event) {
        var record = event.record;

        var weekchars = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
        var date = new Date(record[DATE].value);
        var day = weekchars[date.getDay()];

        var dayEl = document.createElement('span');
        dayEl.textContent = ' (' + day + ')';

        var dateEl = kintone.app.record.getFieldElement(DATE);
        dateEl.appendChild(dayEl);

        return event;
    });
}());

Notes

Make sure to match the Field code, with the Field code written in the code.

 

Refer to the Tutorial page, on how to add scripts to your app.

Was this article helpful?
0 out of 0 found this helpful
Comments
  • Avatar
    玲香

    お世話になっております。
    一覧画面でも曜日表示をするにはどうすればよろしいでしょうか?
    お願いいたします。

    (function() {
    "use strict";

    var DATE = 'due_date'; // field code of date field

    kintone.events.on(['app.record.detail.show','app.record.index.show'], function(event) {
    var record = event.record;

    var weekchars = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
    var date = new Date(record[DATE].value);
    var day = weekchars[date.getDay()];

    var dayEl = document.createElement('span');
    dayEl.textContent = ' (' + day + ')';

    var dateEl = kintone.app.record.getFieldElement(DATE);
    dateEl.appendChild(dayEl);

    return event;
    });
    }());

    Edited by 玲香
  • Avatar
    kintone developer network team

    We appreciate your questions, but could we ask you to post further Japanese inquiries in the Japanese developer network forum.
    https://developer.cybozu.io/hc/ja/community/posts
    You can always reference our article in that community, and there will be many people who can help you out.
    Thanks!

Please sign in to leave a comment.