vb.net IsDate doesnt work for invalid dates [duplicate] - mysql

This question already has an answer here:
Unable to convert MySQL date/time value to System.DateTime.Couldn't store 0/0/0000 0:00:00 value?
(1 answer)
Closed 7 years ago.
In my MySql database i have a date column, then in vb.net i am using this code:
If Not IsDate(reader3.GetDateTime(0).ToString("yyyy-MM-dd")) Then
End If
but if the date in the database is 0000-00-00 its returning an error:
Unable to convert MySQL date/time value to System.DateTime
i have also tried remove the ToString
If Not IsDate(reader3.GetDateTime(0)) Then
End If
but i still get the same error

A way is to use IF into your MySql Select:
IF(YourDateField='0000-00-00' OR YourDateField IS NULL,'',YourDateField) AS YourDateField
So, when the field is null or equal to '0000-00-00', the output from DB will be an empty string and you'll avoid vb.net errors.

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.

mqsql Date conversion [duplicate]

This question already has answers here:
MySQL String to DATE / TIME or TIMESTAMP
(1 answer)
MySQL date conversion
(2 answers)
Closed 1 year ago.
I have a XML XML that we download from a health board.
The date stamp formatted as a string 'Mon, 22 Mar 2021 20:50:32 GMT'
Is there a way to get the proper date on this, when I try using either
CONVERT(BathroomTotal,UNSIGNED) or Str_to_date(LastUpdated,'%M/%d/%Y)
it returns null values - so i am assuming that the initial format is the cause of the issue.
Any help will be appreciated
Tahnks
RB

Convert query with STR_TO_DATE to BigQuery syntax [duplicate]

This question already has answers here:
STRING to DATE in BIGQUERY
(4 answers)
Closed 4 years ago.
I have query that uses the following:
STR_TO_DATE(JSON_EXTRACT_SCALAR(fb.p_dataforanalytics,'$.birthday'), '%m/%d/%Y'),
STR_TO_DATE(JSON_EXTRACT_SCALAR(g.p_dataforanalytics,'$.birthday'), '%Y-%m-%d'),
date_format(p_birthday, '%Y-%m-%d')
This syntax works in MySQL but it doesn't work in BigQuery.
I somehow needs to convert it using PARSE_DATE(?) but I can't find the proper syntax for this.
EDIT:
PARSE_DATE('%m/%d/%Y', JSON_EXTRACT_SCALAR(fb.p_dataforanalytics,'$.birthday') ),
PARSE_DATE('%Y-%m-%d', JSON_EXTRACT_SCALAR(g.p_dataforanalytics,'$.birthday')),
PARSE_DATE('%Y-%m-%d', p_birthday)
Dosent work.
I get:
Invalid result from parsing function
and also
on the p_birthday row:
No matching signature for function PARSE_DATE for argument types:
STRING, INT64. Supported signature: PARSE_DATE(STRING, STRING) at
[15:33]
Easy one, with standard SQL:
#standardSQL
SELECT PARSE_DATE('%m/%d/%Y', '6/22/2017')
2017-06-22
https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#supported-format-elements-for-date
JSON_EXTRACT_SCALAR should work unchanged.

STR_TO_DATE returns blob value [duplicate]

This question already has an answer here:
phpMyAdmin: Date Fields Display as BLOB
(1 answer)
Closed 7 years ago.
I don't understand why mysql returns a blob value here :
SELECT DAT_REAL, STR_TO_DATE(dat_real, '%d-%m-%Y') FROM `entretiens` where dat_real <> ''
from phpmyadmin :
clicking on the blob link leads me to a page saying request =
SELECT STR_TO_DATE(dat_real, '%d-%m-%Y') FROM 'entretiens' WHERE 'entretiens'.'DAT_REAL' = '02-09-2010' AND .'STR_TO_DATE(dat_real, '%d-%m-%Y')' = '2010-09-02';
type of DAT_REAL is varchar(12)
Please specify the data type of "dat_real" field. And also please ensure that it must be a string, since STR_TO_DATE accepts first parameter as a date in string format.

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

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