I’d like to have the ability to display the date in various ways (e.g., {{date:dddd, DD MMM YYYY}} → Saturday, 25 Jan 2025). I’ve found no way to do anything like this in SB yet. Would be useful, I think, for Daily template.
The output of today()
gives the date in this format: 2025-01-25
For getting 25 Jan 2025
, it should be possible to write a space-script function to convert the output of today()
into this format.
After that you could call that space-script function inside the QuickNote template and it should display date like 25 Jan 2025
in all daily quick note pages.
Or if you wanted flexible control over the date formatting, you should be able to design the space-script function accordingly. The input to the space-script function can be the date format specification like you shared, and the function could apply that formatting to the output of today()
.
Maybe this discussion could give some hints: Format today function to YYYYMMDDHHmmss
Is this what you were looking for?
This is a space-script that I use to convert date from ISO to human readable form.
The text is in italian but I think that is simple to translate in english or in other language.
It’s far from perfect but it work for me.
ISO2Date(dataISO, modo = “D2.M2.YYYY”)
Purpose
Converts the date from ISO format to
parameters:
ND => — => Day Year number
D1 => DNN => day
D2 => DN2 => day.toString().padStart(2, ‘0’)
DN3 => days Short Uppercase
DN4 => days Long Uppercase
Dn3 => days Short Uppercase + daysShortUppercase.slice(1).toLowerCase(),
dn3 => days Short Lowercase
Dn4 => days Long Uppercase + daysLongUppercase.slice(1).toLowerCase(),
dn4 => days Long Lowercase
M1 => month
M2 => month 2 digits
MN3 => months Short Uppercase
MN4 => months Long Uppercase
Mn3 => months Short Uppercase + monthsShortUppercase.slice(1).toLowerCase(),
mn3 => months Short Lowercase
Mn4 => months Long Uppercase + months Long Uppercase.slice(1).toLowerCase(),
mn4 => months Long Lowercase
YYYY => year
YY => year toString().slice(-2),
WN => Week number
Example
| Function | Example |
|----------|----------|
| ISO2Date(today())|{{ISO2Date(today())}} |
| ISO2Date(today(), "dn3 D2 Mn3")|{{ISO2Date(today(), "dn3 D2 Mn3")}}|
| ISO2Date(today(), "dn4 D2 mn4")|{{ISO2Date(today(), "dn4 D2 mn4")}}|
| ISO2Date(today(), "M2")|{{ISO2Date(today(), "M2")}}|
Script
silverbullet.registerFunction({ name: "ISO2Date" }, (dataISO, modo = "D2.M2.YYYY") => {
// Converte la data in un oggetto Date
const dateObj = new Date(dataISO);
if (isNaN(dateObj)) {
throw new Error("Data ISO non valida. Verifica il formato (YYYY-MM-DD).");
}
// Funzione per calcolare il numero della settimana ISO
function getISOWeekNumber(date) {
const tempDate = new Date(date);
tempDate.setHours(0, 0, 0, 0);
// Setta il giorno a giovedì (giorno centrale nella settimana ISO)
tempDate.setDate(tempDate.getDate() + 4 - (tempDate.getDay() || 7));
const yearStart = new Date(tempDate.getFullYear(), 0, 1);
const weekNumber = Math.ceil(((tempDate - yearStart) / (1000 * 60 * 60 * 24) + 1) / 7);
return weekNumber;
}
// Giorni della settimana e mesi in vari formati
const giorniCortiMaiuscoli = ["DOM", "LUN", "MAR", "MER", "GIO", "VEN", "SAB"];
const giorniLunghiMaiuscoli = ["DOMENICA", "LUNEDÌ", "MARTEDÌ", "MERCOLEDÌ", "GIOVEDÌ", "VENERDÌ", "SABATO"];
const giorniCortiMinuscoli = ["dom", "lun", "mar", "mer", "gio", "ven", "sab"];
const giorniLunghiMinuscoli = ["domenica", "lunedì", "martedì", "mercoledì", "giovedì", "venerdì", "sabato"];
const mesiCortiMaiuscoli = ["GEN", "FEB", "MAR", "APR", "MAG", "GIU", "LUG", "AGO", "SET", "OTT", "NOV", "DIC"];
const mesiLunghiMaiuscoli = ["GENNAIO", "FEBBRAIO", "MARZO", "APRILE", "MAGGIO", "GIUGNO", "LUGLIO", "AGOSTO", "SETTEMBRE", "OTTOBRE", "NOVEMBRE", "DICEMBRE"];
const mesiCortiMinuscoli = ["gen", "feb", "mar", "apr", "mag", "giu", "lug", "ago", "set", "ott", "nov", "dic"];
const mesiLunghiMinuscoli = ["gennaio", "febbraio", "marzo", "aprile", "maggio", "giugno", "luglio", "agosto", "settembre", "ottobre", "novembre", "dicembre"];
// Estrae giorno, mese, anno e giorno della settimana
const giorno = dateObj.getDate();
const mese = dateObj.getMonth();
const anno = dateObj.getFullYear();
const giornoSettimana = dateObj.getDay();
// Calcolo numero progressivo del giorno nell'anno
const startOfYear = new Date(dateObj.getFullYear(), 0, 1);
const numeroGiornoAnno = Math.ceil((dateObj - startOfYear) / (1000 * 60 * 60 * 24)) + 1;
// Calcolo del numero della settimana ISO
const numeroSettimana = getISOWeekNumber(dateObj);
// Gestione delle sostituzioni nel formato "modo"
const replacements = {
"ND": numeroGiornoAnno,
"D1": giorno,
"D2": giorno.toString().padStart(2, '0'),
"DN3": giorniCortiMaiuscoli[giornoSettimana],
"DN4": giorniLunghiMaiuscoli[giornoSettimana],
"Dn3": giorniCortiMaiuscoli[giornoSettimana][0] + giorniCortiMaiuscoli[giornoSettimana].slice(1).toLowerCase(),
"dn3": giorniCortiMinuscoli[giornoSettimana],
"Dn4": giorniLunghiMaiuscoli[giornoSettimana][0] + giorniLunghiMaiuscoli[giornoSettimana].slice(1).toLowerCase(),
"dn4": giorniLunghiMinuscoli[giornoSettimana],
"M1": mese + 1,
"M2": (mese + 1).toString().padStart(2, '0'),
"MN3": mesiCortiMaiuscoli[mese],
"MN4": mesiLunghiMaiuscoli[mese],
"Mn3": mesiCortiMaiuscoli[mese][0] + mesiCortiMaiuscoli[mese].slice(1).toLowerCase(),
"mn3": mesiCortiMinuscoli[mese],
"Mn4": mesiLunghiMaiuscoli[mese][0] + mesiLunghiMaiuscoli[mese].slice(1).toLowerCase(),
"mn4": mesiLunghiMinuscoli[mese],
"YYYY": anno,
"YY": anno.toString().slice(-2),
"WN": numeroSettimana // Aggiunto il numero della settimana
};
// Gestione dei separatori accettati
const separatorRegex = /[./\- '()]+/;
const parts = modo.split(separatorRegex);
let result = modo;
parts.forEach(part => {
if (replacements[part]) {
result = result.replace(part, replacements[part]);
}
});
return result;
});