SQL Convert 'mm/dd/yy' string to date format - mysql

I have table named templog and I have a date column named 'tdate' which stores a string in the 'mm/dd/yy' format. I tried to convert using the following syntax but I receive an error.
SELECT convert(datetime,tdate,110) from templog
SQL query: Documentation
SELECT convert(datetime,tdate,110) from templog LIMIT 0, 25
MySQL said: Documentation
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'tdate,110) from templog LIMIT 0, 25' at line 1
Any ideas on what I'm doing wrong?

For MariaDB, you want str_to_date():
SELECT str_to_date(tdate, '%m/%d/%y')
FROM templog

Related

MySQL: Error when running a Windowing query

I am trying to execute a WINDOW query which is given below:
SELECT
DATE(ts),
oi,
avg(oi) OVER(PARTITION BY DATE(ts) )
FROM bybit_oi_1d_BTCUSD
It gives the following error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(PARTITION BY DATE(ts) )
FROM bybit_oi_1d_BTCUSD LIMIT 0, 25' at line 4
No Window functions until MySQL 8+ or MariaDB 10.2

Use convert statement in SQL : Error

I am receiving an error as I try to convert my datetime column called rent_date to mm/dd/yyyy format.
I have consulted the relevant documentation but still receive error.
SQL statement:
SELECT listing.title , listing.author, listing.isbn, listing.cond , listing.additional_information, CAST(rented_listings.due_date as date), CONVERT(date, rented_listings.rent_date, 101)
FROM `listing`
INNER JOIN `rented_listings` ON `listing`.`upload_id` = `rented_listings`.`upload_id`
WHERE `availability`= 'R' ORDER BY `rented_listings`.`due_date` ASC , `rented_listings`.`rent_date` DESC
Error is within this part of the query
CONVERT(date, rented_listings.rent_date, 101) which makes sense because when I take it out the query works.
How do I convert 'rented_listing.rent_date' to mm/dd/yyyy?
EDIT:
Specific error included:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
'rented_listings.rent_date, 101)
FROM listing
INNER JOIN`' at line 1
I think you should do like this in mysql
DATE_FORMAT(cast(rented_listings.rent_date as date), '%m/%d/%Y');
which will first convert it to the date and then to the specific format

MySQL Getting the return of a substraction

We are trying to get the length of a physical exercise by using the timestamps on our sensor data.
We currently have the following query:
SELECT UNIX_TIMESTAMP(
SELECT HAAS2.trainingsdata.timestamp
FROM HAAS2.trainingdata
WHERE HAAS2.trainingsdata.training_id= 1
ORDER BY timestamp DESC LIMIT 1)
- UNIX_TIMESTAMP(
SELECT HAAS2.trainingsdata.timestamp
FROM HAAS2.trainingdata
WHERE HAAS2.trainingsdata.training_id= 1
ORDER BY timestamp ASC LIMIT 1)
AS output
(enters added for readability)
When testing this query in phpMyAdmin we get the following error:
#1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'SELECT HAAS2.trainingsdata.timestamp FROM HAAS2.trainingdata
WHERE HAAS2.trainin' at line 1
We've tried different ways to write down the query all resulting in the same error. We don't understand where the syntax error lies.
SELECT max(UNIX_TIMESTAMP(timestamp)) -
min(UNIX_TIMESTAMP(timestamp)) AS output
FROM HAAS2.trainingdata
WHERE training_id = 1

Mysql error in select statement for date type column

SELECT DAY_ADD(DATE(scp.create_date),INTERVAL scp.subscription_period_days DAYS)
FROM `subscription` scp;
I am getting error as :
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
near 'DAYS) FROM subscription scp
what would be solution if I am adding days using some column values. should I use some other mysql function. Please rectify.
Try this one:
SELECT DAY_ADD(scp.create_date,INTERVAL scp.subscription_period_days DAY)
FROM `subscription` scp;
INTERVAL DAY instead of DAYS should work better.

MySQL SELECT with fields less and greater than values

I am trying to do a select query on MySQL with phpMyAdmin or PHP with PDO.
SELECT 'uid' FROM 'clusters' WHERE 'lat'<='47.21125' AND 'lat'>='39.21125' AND 'lng'<='32.90243' AND 'lng'>='22.90243'
However, phpMyAdmin says:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''clusters' WHERE 'lat'<='47.21125' AND 'lat'>='39.21125' AND 'lng'<='32.90243' A' at line 1
What is wrong with it?
'' creates a string literal in MySQL, so your query is selecting the literal "uid" from the literal "clusters," which is invalid. Use backtics (or nothing)
SELECT Uid FROM clusters WHERE lat <= 47.21125 AND lat >= 39.21125
AND lng >= 22.90243