Calc - defining a specific year to autofill in dates

I’ve recently migrated from openoffice to libreoffice (I rarely used the former, so was blissfully unaware of the long-since abandoned nature) and did however run into the same issue.

For my documents, whenever I enter a day and month, it enters the current year. So far so simple, though if I set up documents with dates of previous years, it ends up with some extra repetitive intputs and room for errors, so I would like ask:
Is there a way to tell libreoffice “assume year X for all dates in this document”?
I tried searching a good while, but found nothing of the sort, so figured I’d put in a direct question. And yes, typing in 1.1.22 is simple, but I’m forgetful and error prone, so telling LO “always use 2022 for dates in this document” would be a nice convenience for me.

The LibreOffice parameter is this: if the year is current, it is not necessary to type it, if different it is mandatory to type it. I don’t know any alternative.

So we could change the date in the OS back to 2022, then Calc would use it. But as it is necessary to set date back after work I’m not sure, if this is a solution, if one tells

(Also a problem: Changing system date also affects the date for the document on disk, wich may give problems with backup-schemes…)

What if we did things differently and said, “Please, Calc, reassign all dates in this document (in this active sheet?), whatever they are, to year XXXX”? Or “Please circle in red oval all the cells where the date does not correspond to the year XXXX”?

1 Like

Data validation and conditional formatting could be quite useful here…

1 Like

Before saving, you can search for all [0-9]{4} and replace with 2022.
Maybe adding a dot before (\.[0-9]{4}) if the year are shown as .2022.

Activate the macro by double-clicking on the desired cell, already formatted with date.

Link the macro to the Spreadsheet Event, double click.

Sub InputDiaMes
Dim sData As String
xDia = InputBox ("Day", "Type")
xMes = InputBox ("Month", "Enter")
xAno = 2022 '<===== year =============
xData = xMes &"/"& xDia &"/"& xAno
'MsgBox xData
	ThisComponent.getCurrentSelection().Formula = xData
End Sub

Psistorm.ods (9,5,KB)