I want to create query to Automatic add 2 days to column name (start_time) in format 2020-07-01 07:00 pm i want the new output to be in same format (2020-07-01 07:00 pm)
How about that:
SELECT DATE_ADD("2020-07-01", INTERVAL 2 DAY);
Related
I am working in mySQL and I currently have a count of total orders by day, but I would like to add Saturday and Sunday orders to Monday then remove Saturday and Sunday values. I have done some research on this but I cannot seem to find anything similar to what I am trying to do.
My current data table looks like this:
Date | Daily Count
8-6-2020 25
8-7-2020 82
8-8-2020 24
8-9-2020 33
8-10-2020 18
8-11-2020 10
8-12-2020 25
8-13-2020 15
I need it to look something like this:
Date | Daily Count
8-6-2020 25
8-7-2020 82
8-10-2020 75
8-11-2020 10
8-12-2020 25
8-13-2020 15
In this one the Daily counts for the 8th and 9th are added to the 10th, then removed, because they are weekend days. Thank you in advance for your help!
Consider using a case expression to adjust the date:
select
case weekday(date)
when 5 then date + interval 2 day
when 6 then date + interval 1 day
else date
end as new_date,
sum(daily_count) as daily_count
from mytable
group by new_date
My table
starttime | endtime | id
10:30 11:30 1
11:30 12:30 2
14:30 16:30 3
15:30 16:30 4
I need to find the id in a given time slot for example
say
10:30 to 13:30 should give me o/p 1 2
11:30 to 16:30 should give o/p 2 3 4
The statement I am using
select id from table where STR_TO_DATE(starttime,'%h:%i')>='10:30' and STR_TO_DATE(endtime,'%h:%i')<='22:30';
it gives me only 1 and 2
I am not able to get the correct output what am I doing wrong here?
Note start and end time in varchar
EDIT-
If I wanted to selectthe id's between 10:30 to 12:30 I use this below command
select id from table where STR_TO_DATE(starttime,'%H:%i')>='10:30' and STR_TO_DATE(endtime,'%H:%i')<='12:30';
This gives me only id 1 .. but not giving me 2, If i change 12:30 to 12:40 it gives me 1 & 2.BUt I am using less or equal so it should give me both the id's right? Why its not working like that?
STR_TO_DATE(starttime,'%h:%i')
You are using the format %h which according to the documentation is for:
Hour (01..12)
Essentially, everything above 12 is invalid (Returns NULL).
And, you gave values above 12 to those ids.
Use the specifier
%H
for hours in the format 00 - 23
or the specifier
%k
for hours 0 - 23.
I need to modify several dates in a table using a mysql update statement.
Here is the problem: I need to modify each date adding 1 month and setting the day to 7.
Rule: +1 month and day needs to be 7
2015-10-10 => 2015-11-07
2015-11-05 => 2015-12-07
2015-12-21 => 2016-01-07
....
It's pretty easy do add a month, i've already tried using DATE_ADD(eventdate, INTERVAL 1 MONTH) but i need to change the day as well.
Started building the following query:
UPDATE receipts SET due_date = DATE_ADD(due_date, INTERVAL 1 MONTH) WHERE ...
Now i need to change the day.
How to do that? Thanks
You can try this (don't forget to add your WHERE clause):
UPDATE receipts
SET due_date = CONCAT(DATE_FORMAT(DATE_ADD(due_date, INTERVAL 1 MONTH), '%Y-%m-'), '07')
I have one table with 30 entries and date column is like following
2014-11-01
2014-11-02
2014-11-03
.
.
.
2014-11-30
Now i want to write MySQL query to update month from 11 to 10 or you can say from month November to October.
I want to change only month in all these dates from 11 to 10.
Use DATE_ADD function for changing the month and MONTH function for filtering the records. Assuming the table name is tbl and the column name is date, here's what the query will look like
UPDATE `tbl`
SET `date` = DATE_ADD(`date`, INTERVAL -1 MONTH)
WHERE MONTH(`date`) = 11
I have the following (MySQL) table called "tweets":
tweet_id created_at
---------------------
1 1298027046
2 1298027100
5 1298477008
I want MySQL returning the number of tweets per day of the week; taking the above data it should return:
Sunday 1
Monday 2
I now have the following query to accomplish this:
SELECT COUNT(tweet_id) AS tweets, DAYNAME(FROM_UNIXTIME(`created_at`)) AS day
FROM tweets
GROUP BY day
ORDER BY DAYOFWEEK(day)
This however returns a list that starts with Wednesday:
Wednesday 2019
Tuesday 2072
Monday 932
Sunday 1433
Saturday 4321
Friday 643
Thursday 1542
How is this list ordered? Why not just Sun to Sat and how * can * I accomplish that?
DAYOFWEEK takes a date ('2011-02-26'), but you're giving it a day name ('Saturday').
Try to change the order clause like this
order by dayofweek(FROM_UNIXTIME(`created_at`))