MySQL: Convert from Varchar to Date and applying Date_Sub
NickName:Java Ask DateTime:2020-10-15T02:25:55

MySQL: Convert from Varchar to Date and applying Date_Sub

I am trying to use 'date-sub' to subtract few month using MySQL.

Before I do that, I figure I have to covert varchar(7) value into date format first. So, I used following:

 select str_to_date('7-2016', '%m-%Y');  -- 2016-07-00 (result)

The result was ok, but I am not sure why I get '-00'.

Now, I am trying to apply date_sub:

 select date_sub(str_to_date('7-2016', '%m-%Y'), interval 11 month);

Why do I get null data?

Copyright Notice:Content Author:「Java」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/64359391/mysql-convert-from-varchar-to-date-and-applying-date-sub

More about “MySQL: Convert from Varchar to Date and applying Date_Sub” related questions

MySQL: Convert from Varchar to Date and applying Date_Sub

I am trying to use 'date-sub' to subtract few month using MySQL. Before I do that, I figure I have to covert varchar(7) value into date format first. So, I used following: select str_to_date('7-20...

Show Detail

DATE_SUB problem

my code: $song = mysql_query("SELECT COUNT(*) FROM `".$this->prefix."playlist` WHERE `time` > DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 20 MICROSECOND) AND `long` < DATE...

Show Detail

Error in MySQL to HiveQL Conversion including DATE_SUB and INTERVAL

I am trying to convert the query written in MySQL to HiveQL The part of query giving me error is : WHERE 1 = 1 AND table1.incoming_date >= DATE_SUB(DATE_SUB(CURDATE(),INTERVAL DAY(CURDATE()) -...

Show Detail

mysql match by date using date_sub

I have this mysql query SELECT * FROM all_sent_Orders a WHERE a.nachforschungCompletedOn IS NULL AND CASE WHEN a.lastMessageSent IS NOT NULL AND a.lastResponse IS NULL THEN date(da...

Show Detail

MySQL - Search Query between DATE_SUB() AND DATE_SUB() Error

I am trying to do a search query (using pdo php and mysql) between a date range which is between (date-7days) and (date-1day) using DATE_SUB() on both so for example: end_date is 2013-03-26 search

Show Detail

How to exclude weekends from DATE_SUB in mysql

Does anyone know how to exclude weekends from the DATE_SUB function in MYSQL? I am looking to search the past 1500 working days from CURDATE() but am struggling with the solution? Much appreciate ...

Show Detail

mySQL convert varchar to date

I need to convert a varchar value of 1/9/2011 to a date in mySQL and I want only the month and year. So that I can then use the PERIOD_DIFF function (so I would need the above to be converted to 2...

Show Detail

mySQL convert varchar to date

I need to convert a varchar value of 1/9/2011 to a date in mySQL and I want only the month and year. So that I can then use the PERIOD_DIFF function (so I would need the above to be converted to 2...

Show Detail

DATE_SUB & DATE_ADD mysql

I have a requirement wherein email notification should be sent via a workflow in each of the following three cases, 2 months prior to 6 month probation end from start date 3 weeks prior to 6 month

Show Detail

convert from MySql date query to mongoDB date query

I used This format in MySql to get data in one week and in one mounth date > DATE_SUB( NOW(), INTERVAL 1 WEEK) // for one week date > DATE_SUB( NOW(), INTERVAL 1 MONTH) // for one month h...

Show Detail