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.
Related
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.
This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 4 years ago.
First time posting so forgive me if I omit anything. I have been struggling to Transfer data from one table to another in MySQL Community Server - GPL Version: 8.0.11. To better set the scene I import data from a MongoDB and then perform the STR_TO_DATE function and then need to move specific columns to another table one of which is one of the DATETIME data typed columns whenever I run the command/query. Here is the code :
INSERT INTO mlb.hazards
SELECT '_id', 'Source', 'CreatedTime', 'AlarmId', 'Description'
FROM mlb.incident_20181007
WHERE Description = 'ALARM ON Runway Hazard 27R 9L';
I get the return error message:
Error Code: 1292. Incorrect datetime value: 'CreatedTime' for column 'CreatedTime' at row 120 0.000 sec
I dug up the data for CreatedTime and _id for row 120 and this is what I found.
Data copied from Mysql workbench:
'2018-07-03 13:35:41.421000', '621E30C4401749328035E215E680CA6A'
The columns data types are listed as DATETIME in both tables, please help me understand what I'm missing here. Thank you in advance.
This is probably a simple issue of you passing a string instead of a column value. It looks like you're trying to insert the values of columns from your incident table (eg column _id, Source, etc). However, because you have then wrapped in single quotes, you are actually passing the literal string value. In other words, it's trying to insert the string "CreatedTime" instead of the datetime value that is in that column.
Instead of single quotes, mysql uses backticks. Your query should be:
INSERT INTO mlb.hazards
SELECT
`_id`, `Source`, `CreatedTime`, `AlarmId`, `Description`
FROM
mlb.incident_20181007
WHERE
`Description` = 'ALARM ON Runway Hazard 27R 9L';
This question already has answers here:
How to convert a string to date in MySQL?
(5 answers)
Closed 5 years ago.
I have a column(string (8)) that contains data like 12032008 and I have to display it as 12/03/2008. What should I do in retrieve query?
In mysql first convert it to date object using STR_TO_DATE then to format use DATE_FORMAT
SELECT DATE_FORMAT(STR_TO_DATE('12032008','%d%m%Y'),'%d/%m/%Y')
But ideally you should not save the date or date time as strings in table it will make things complex for mysql and for you also
Demo
The most appropriate thing for you to do here would be to stop storing date information in text columns. Instead, put 12032008 into a bona fide datetime column. This will make your life easiest in the long run. If you can't do that in the short term, here are two options for you to consider.
The short way, just using base string functions:
SELECT
CONCAT(LEFT(col, 2), '/', SUBSTRING(col, 3, 2), '/', RIGHT(col, 4)) AS output
FROM yourTable;
The longer way, and probably the better long term solution, would be to first convert your date string into a date, then convert it back to a string using the formatting you want:
SELECT
DATE_FORMAT(STR_TO_DATE(col, '%d%m%Y'), '%d/%m/%Y') AS output
FROM yourTable;
Demo
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.
This question already has answers here:
How can I make SQL case sensitive string comparison on MySQL?
(12 answers)
Closed 8 years ago.
I have a Login table in MySql database . . In table there is a column by cname and one of the value is 'Raghu'. My question is when i write the query as
Select *from Login where cname='raghu';
Then it is retrieving the record which contains 'Raghu' . I want it to retrieve according to case . How can I retrieve with case sensitively, values in the data of tables.
Use: 10.1.7.7. The BINARY Operator
The BINARY operator casts the string following it to a binary string. This is an easy way to force a comparison to be done byte by byte rather than character by character.
Select * from Login where binary cname='raghu';
SELECT * from Login WHERE STRCMP(cname,'Raghu')=0;
Can you try this, you can use LOWER FUNCTION in either column name LOWER('cname') or in value LOWER('raghu');
Select *from Login where LOWER(`cname`) = 'raghu';