Unable to convert MySQL date/time value to System.DateTime vb.net - mysql

am having a problem with my application in vb.net where by when i insert my date from a datetimepicker to a mysql database the value which i see is 0000-00-00 and when i try to retrieve that record i get the following error message -
Unable to convert MySQL date/time value to System.DateTime

In MS-SQL I insert my dates using a CONVERT(datetime, datetimepicker.value, 103) The 103 sets the format to DD/MM/YYYY HH:MM:SS.sss.
You may have to do something similar

Related

How to convert date from MM/dd/yyyy to yyyy-MM-dd in MySQL? Error: 1411. Incorrect datetime value: '' for function str_to_date

I just need help on how to convert date from MM/dd/yyyy to yyyy-MM-dd in MySQL?
I already asked this question a few months ago, and I was able to successfully convert it. Please see thread here.
However, I'm having difficulty with this new dataset. Previously, when I created thie previous post, ALL of my dataset were in the format MM/dd/yyyy, to which I successfully converted to yyyy-MM-dd using the following query:
Update human_resources.timekeeping Set Actual_Date = str_to_date(Actual_Date,'%m/%d/%Y');
However, for this new problem that I am encountering, I have a mix of data format in one table. Some time entries are in the format of MM/dd/yyyy while some are in the format yyyy-MM-dd. (Datatype is VARCHAR)
I need to change my old format MM/dd/yyyy to my new format yyyy-MM-dd.
I'm trying to use the same query:
Update human_resources.time_entry_request Set Actual_Date = str_to_date(Actual_Date,'%m/%d/%Y');
but I'm encountering the following error:
Error Code: 1411. Incorrect datetime value: '2021-05-08' for function
str_to_date
On the other hand, I tried to use this query: (Specified the actual date in the where clause)
Update human_resources.time_entry_request Set Actual_Date = str_to_date(Actual_Date,'%m/%d/%Y') where Actual_Date = "05/31/2021";
and it was successful. (Changing specific MM/dd/yyyy time entry to format yyyy-MM-dd).
I believe the error that is causing this problem is that the dataset already contains the new and accurate format which is the yyyy-MM-dd.
It also happens vice versa, tried to change the new format into the old one so I can change them to the new one altogether.
PS. The data type for Actual_Date is VARCHAR. I tried changing it to DATE() but am receiving this error:
Executing:
ALTER TABLE `human_resources`.`time_entry_request`
CHANGE COLUMN `Actual_Date` `Actual_Date` DATE NULL DEFAULT NULL ;
Operation failed: There was an error while applying the SQL script to
the database.
ERROR 1292: Incorrect date value: '06/04/2021' for
column 'Actual_Date' at row 17
SQL Statement:
ALTER TABLE `human_resources`.`time_entry_request`
CHANGE COLUMN `Actual_Date` `Actual_Date` DATE NULL DEFAULT NULL
Is there a way I can change the old format to the new one, please? Would really appreciate your help! The dataset contains a mix of MM/dd/yyyy while some are in the format yyyy-MM-dd
My previous post contains ALL MM/dd/yyyy so I was able to convert it successfully.

How to convert nodejs string To mysql?

I am trying to put a date to my mysql database. The column type is date.
the value of orderDate is '2018-04-18' however after putting it into the database it is changed to 1997-00-00 why is that and how can i get the actual value into the database?
This is the function I used: STR_TO_DATE(${orderDate}, "%Y-%M-%D");
If I dont use the function I get an error saying 1997 is an invalid date.

SSRS issue matching date with parameters

I have a SSRS report using an ODBC connection with MySQL. I have a problem to match the date with the parameters. When I type a date manually in the query it works fine, no problem. But when I use the parameters, it doesn't return anything. One thing I found is that the date data returned is under the format YYYY-MM-DD and the date from parameter is DD/MM/YYYY. I tried CONVERT and STRING_TO_DATE functions of MySQL but no luck. Any clue?
convert the parameter value to a date based on the format sent from the SSRS to match the format you are using in the manual test.
Converting a date in MySQL from string field

MySQL DATE type value gets displayed with hours/minits/seconds, however its is not stored like that in the database

I have DATE type column in a MySQL database table with dates stored in it. I am using the YYYY-MM-DD format when I upload the dates to the database.
When I check the values they are stored in the correct and expected format (2005-01-02), however when I am attempting to read these values with my C++ program I am receiving something like this: 02/01/2005 00:00:00
I don't really understand the reason, I thought in the DATE type only the YYYYMMDD gets stored without the time. The other weird thing is the reformatting I thought YYYY-MM-DD is an accepted format.
Here is my code:
String^ getDateOfBirth = myReader->GetString("player_date_of_birth");
DateOfBirthLabel->Text = getDateOfBirth;
I am using Visual Studio 2013.
Any help would be appreciated.

MySQL - How to parse a string value to DATETIME format inside an INSERT statement?

I have a MySQL database, with a column that is date type DATETIME.
I am getting a string value for a date / time from an external application. That string value looks like this:
'5/15/2012 8:06:26 AM'
MySQL throws an error on the INSERT: "Error. Incorrect datetime value". My workaround was to change the column type to VARCHAR, which works, but I really need the data as a proper Date & Time for future use.
I researched accepted formatting for MySQL DATETIME values, and found that MySQL wants the DATETIME format as 'YYYY-MM-DD HH:MM:SS'.
I can't change the external application to reformat the date / time string in a format, so my only chance is to deal with it.
What I need to do, I think, is parse the existing string, using MySQL syntax, inside of my INSERT statement, but I'm not sure how to do that. I have some idea that I need to use a SELECT clause, perhaps STR_TO_DATE, somehow in combination with my INSERT statement.
Here is my current INSERT statement. I removed the other fields that are not causing a problem, just to make the example clean.
INSERT INTO tblInquiry (fldInquiryReceivedDateTime) VALUES ('5/15/2012 8:06:26')
Use MySQL's STR_TO_DATE() function to parse the string that you're attempting to insert:
INSERT INTO tblInquiry (fldInquiryReceivedDateTime) VALUES
(STR_TO_DATE('5/15/2012 8:06:26 AM', '%c/%e/%Y %r'))