0

I am having a bit of a problem when saving times/dates to MariaDB. Because of the UTC format that dates and times are saved it can save times 1 hour behind and dates can be saved as the previous day.

Most of the work arounds I have seen, involve pulling the data back from the DB and converting it, however I was keen to save it to the DB with the correct dates/times already entered.

I done this using {{moment.utc("Date_Entry").tz("Europe/London").format()}}

The problem I have at the minute, though, is... If I want to leave the date/time empty, the function above saves the current date/time.

Ideally I would like to handler the UTC conversion if required, but if the entry is empty, save a NULL value to the DB

Does anyone know of a better solution than what I have currently?

PaulMcF87
  • 385
  • 5
  • 18
  • there is a format that saves the time zone, and from there you can convert it, in then usal cases you want all members to have the same time, so utc is saved and the local system automatically transforms into local time – nbk Sep 17 '22 at 16:48
  • This question might shed a light in the timezones: https://stackoverflow.com/questions/2934258/how-do-i-get-the-current-time-zone-of-mysql. Can you share the output from: `select timediff(now(),convert_tz(now(),@@session.time_zone,'+00:00'));`??, and some more details about your application ? – Luuk Sep 17 '22 at 16:54
  • @Luuk The saved data will be pulled using different applications so the select function will vary depending on the application being used at the time (For workers/customers etc...) The goal here is to save the time to the correct value which should save on customising the select functions. The function which I have above works when I enter a time to save but it doesnt like an empty (NULL) value and instead adds the current time which I would prefer that it didnt – PaulMcF87 Sep 17 '22 at 17:10
  • Please share the code of this `moment` function/functionality – Luuk Sep 17 '22 at 17:19
  • What's the data type of the column? `TIMESTAMP` is unfortunately not great for this. – The Impaler Sep 17 '22 at 22:12

0 Answers0