0

I want to store the output of Angulars MatDatepicker in MySQL. The issue is that the formats are not matching. Here an example when the user picks 13.11.2020:

MatDatepicker returns the Date in the following format (with timezone):

2020-11-12T23:00:00.000000Z

MySQL use datetime as format. The raw value in the db is the same (but without timezone):

2020-11-12 23:00:00

This is the query which I use to insert the datetime:

INSERT INTO testtable (`datetime`) VALUES('2020-11-12T23:00:00.000000Z');

The issue is that on return to the frontend, the 12. of november is displayed. I have a huge Formular with a lot of Datepicker. That's why I don't want to format the date by Angular. Is there a solution how I can solve that by MySQL?

Nico Schuck
  • 832
  • 3
  • 15
  • 32
  • You are not adding from angular to mysql? you are posting to api right? – flakerimi Nov 16 '20 at 16:30
  • Does this answer your question? [How to change Mat-Datepicker date format to DD/MM/YYYY in simplest way?](https://stackoverflow.com/questions/55721254/how-to-change-mat-datepicker-date-format-to-dd-mm-yyyy-in-simplest-way) – flakerimi Nov 16 '20 at 16:33
  • Or if there no business issue you can store the date in the form of text. – user3315556 Nov 16 '20 at 18:13

1 Answers1

0

Could you please try something like this:

insert into test_table_name (datetime_column) values (CAST(left('2020-11-12T23:00:00.000000Z',19) AS datetime));
allenski
  • 1,652
  • 4
  • 23
  • 39