Comments - Datetime format YYYYMMDD hh:mm:ss.fff

3 years, 9 months ago Jan Steinman

As far as I know, INSERT expects dates/times in standard ISO-8601 format (https://en.wikipedia.org/wiki/ISO_8601). That requires a dash between the parts of the date.

So you will have to convert '20210315' to '2021-03-15' before feeding it into INSERT.

I'm not as familiar with the time format, which may require massaging, as well.

 
3 years, 9 months ago Ian Gilfillan

The earlier comment is correct, and you need to convert the data to the standard format. If you must do this on the MariaDB side, something like

INSERT INTO t (ID, Value, Date) VALUES 
  ('Test1', '33', CONCAT(SUBSTR('20210315 11:15:27.059',1,4),'-',SUBSTR('20210315 11:15:27.059',5,2),'-',SUBSTR('20210315 11:15:27.059',7)));

should work assuming the dates you are inserting are always in that same format.

Also note, TABLE is a reserved word, so you probably don't want to be using it as the table name.

 
3 years, 9 months ago happy said

thank you for your answer, but what I need is not to change the insert query that I am using, if there is an option in the Database that allows us to change the time format it will be easier.

 
3 years, 9 months ago Jan Steinman

Can't do that, as you've been told several times.

It's time for "Plan B."

People who ask for advice shouldn't have a foregone conclusion that they're stuck on.

 
3 years, 9 months ago Ian Gilfillan

No, since what you are attempting to insert is not a valid datetime, the only other alternative would be to make the field a string.

 
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.