Add seconds in the card creation data column

Is it possible to add a snippet of code to allow the Anki browser to show seconds in card creation date hours? Natively Anki only shows hours and minutes.

I’m posting the complete code here of the addon that I want to modify and the code is in the addon’s __ init

I tried through ChatGPT, but Chat GPT couldn’t do it.

Criated Date

from aqt import gui_hooks
from aqt.qt import QAction
from aqt import mw

from . import set_added_date

def setupAction(browser):
    actionSetAddedDate = QAction("Set Added Date...", browser)
    actionSetAddedDate.triggered.connect(lambda: set_added_date.setAddedDate(browser))

    browser.form.menu_Cards.insertAction(browser.form.menu_Cards.actions()[2], actionSetAddedDate)

1 Like

This is a complete add-on to do that:

import datetime
from typing import Sequence

from aqt import gui_hooks, mw
from aqt.browser import CellRow, ItemId
from aqt.qt import *

def on_browser_did_fetch_row(
    card_or_note_id: ItemId, is_note: bool, row: CellRow, columns: Sequence[str]
) -> None:
        idx = columns.index("noteCrt")
    except ValueError:
    if is_note:
        note = mw.col.get_note(card_or_note_id)
        created_date = datetime.datetime.fromtimestamp( // 1000)
        card = mw.col.get_card(card_or_note_id)
        created_date = datetime.datetime.fromtimestamp( // 1000)

    row.cells[idx].text = created_date.strftime("%Y-%m-%d @ %H:%M:%S")


So instead of me adding a snippet of code to a part of the add-on I gave above, should I just create a new add-on with the code you provided?

Part of the code I indicated above is from an add-on that changes the card creation date. I thought it would be convenient to just add this function of showing seconds to this add-on, as it is a function that would make it easier for me to use and I miss this function in this add-on.

I recommend adding it as a new add-on. It’s self-contained and shouldn’t interfere with the other add-on.

1 Like

I managed to run it as an add-on. I’m happy, it’s working perfectly.

Thank you very much for taking the time to help me.

1 Like

Just a note: does anki store milliseconds as well? Did you tell me if it would be possible to add within the code to show the milliseconds as well?

In the add-on that changes the card’s creation date, when the change is made in bulk (multiple cards), the creator said that millisecond difference is added to each card.

I tried “.%f” after “%S” in (“%Y-%m-%d @ %H:%M:%S”), but it showed “H:M:S.000000” in the card creation date column.

Also replace // with just / in // 1000.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.