Skip to content

[FEATURE] Supply date tag #298

Description

@sciurius

Script name

journal_entry

Script authors

@pbek @sanderboom @kantrol @nico2sh

Desired behavior

When a new journal entry is created, automatically add a tag that reflects the date. Preferrably customizable similar to the title, i.e. with YYYY, MM, etc substitutions.

Suggestion

Several scripts have a hard coded formatDate function. It may be worth to centralize this function or use a strftime library.

Activity

  1. pbek commented on Sep 29, 2026

    @pbek
    Member

    There's no need for a custom formatDate function in the scripts, because the QML engine QOwnNotes scripts run in already has one built in: Qt.formatDateTime (plus Qt.formatDate and Qt.formatTime).

    var date = new Date();
    
    Qt.formatDateTime(date, "yyyy-MM-dd");                     // 2026-09-29
    Qt.formatDateTime(date, "yyyyMMdd");                       // 20260929
    Qt.formatDateTime(date, "yyyyMMddHHmmss");                 // 20260929140512
    Qt.formatDateTime(date, "dddd, d. MMMM yyyy 'at' HH:mm");  // Tuesday, 29. September 2026 at 14:05
    
    // Tag the current note with a date tag, like "2026-09"
    script.tagCurrentNote(Qt.formatDateTime(date, "yyyy-MM"));

    Common placeholders are yyyy, yy, MM, M, MMM, MMMM, dd, d, ddd, dddd, HH, hh, mm, ss and AP. Text in single quotes is output literally. The placeholders are case-sensitive: MM is the month and mm is the minute. YYYY/DD from strftime or moment.js are not supported, and neither are ISO week numbers.

    For all placeholders see the Qt docs:

    I've added a Formatting dates and times section to the scripting documentation, and the example scripts in the QOwnNotes repository now use Qt.formatDateTime instead of formatting dates by hand. The docs page will show up once the documentation is deployed.

    Adding a configurable date tag to journal_entry is now easy, and scripts in this repository with their own hard-coded formatDate can switch to Qt.formatDateTime over time.

  2. sciurius commented on Sep 29, 2026

    @sciurius
    ContributorAuthor

    Thanks for this info. This is precisely what I needed!

  3. added 4 commits that reference this issue on Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions