mqsql Date conversion [duplicate] - mysql

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

Related

'OPENJSON' is not a recognized built-in function name [duplicate]

This question already has answers here:
Apply OPENJSON to a single column
(2 answers)
How to parse JSON column to a table with TSQL
(4 answers)
Closed 7 months ago.
I'm using Microsoft SQL Server 2019 - 15.0.4236.7 (X64)
Compatibility Level is 2019 \ 150
I have a very simple query to transpose some JSON that is stored in a column:
SELECT OPENJSON ([fieldname])
FROM mytable
But I keep recieing the error:
'OPENJSON' is not a recognized built-in function name.
Do I need to enable something?

How to convert date-time string in to date-time format using sql [duplicate]

This question already has an answer here:
Converting dates in MySQL
(1 answer)
Closed 3 years ago.
I want to convert a date-time column of type string into datetime format. The columns is in 12-hour format and uses AM and PM to show time.
Here is the input and expected output
6/21/2019 2:57:55 PM -> 6/21/2019 14:57:55
6/21/2019 3:12:19 PM -> 6/21/2019 15:12:19
6/21/2019 3:19:31 AM -> 6/21/2019 3:19:31
You can try using STR_TO_DATE()
select STR_TO_DATE('6/21/2019 2:57:55 PM','%m/%d/%Y %r')

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.

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

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.

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.