I have found similar answers but I didn't find exact one, so I am starting a new question.
I have a little app for a mechanic shop, where the user can input information about the car, such as registration number, a name of the owner, date when the car was on service ( an auto added/updated field in MySQL).
My question is since all cars must do a service inspection again in 6 months, how can I after 5 months print out information that in next 30 days XY cars needs to make a new inspection?
EDIT:
*SELECT * FROM vozila where DATE_ADD(DATE(datum), INTERVAL 6 MONTH) = CURDATE()*
In case above, it is displaying only 5-month-old serviced cars from current date, but I need to set it to display notification 5 months after, and that that results stay on page for next 30 days (untill month 6th).
Let's say that some XY car was on the mechanic service at 1.1.2017... At 1.6.2017 on notification.php page there would be "Cars with expiration date in next 1 month:" table and on it would be all cars that are 1 month left up to 6th when then need to do it again.
"SELECT * FROM vozila where datum < date_sub(now(), interval 11 month)"
Related
I am basically trying to get my app to report when items are not returned or overdue in a 5 day and 15 day window. After much trial and error the below coded is the best I could come up with. However, when I extend to 15 days I still receive items that were returned (hence not exists not working appropriately) based off of movieid. The goal is see items from checkout that have not been returned with a time frames to notify members of late dates. Any suggestions to improve this statement?
select movieid, dueback
from checkout as a
where NOT exists
(
select * from returns as b
where a.movieid = b.movieid
AND dueback < DATE_SUB(NOW(), INTERVAL 5 DAY)
)
ORDER by dueback;
CHECKOUT TABLE: checkoutid, outdate, dueback, movieid, customerid, payment
RETURNS TABLE: returnid, today, movieid
You can use BETWEEN using the two computed dates. See Between documentation, but you can do something like:
AND dueback BETWEEN DATE_SUB(NOW(), INTERVAL 5 DAY) AND DATE_SUB(NOW(), INTERVAL 15 DAY)
That way you will get all dueback that is between 5 and 15 days from it's date.
Count all dates of the last 3 years - completed (if all reports have been submitted) and not completed (if one report is missing) and output it as a list.
There is a table with the appointments.
Each appointment has a date and an ID.
For each appointment, there are events (table 2 with the ID of the appointment), which are concluded with a report. Only if all events have a report (in table 2 "Report available?" = 1), then the appointment is closed, otherwise, it is still open.
I want to point out the last three years for example:
2019 x closed appointments from appointments...
2018...
2017...
I thought I'd count the related events and take the sum of the submitted reports. This also works for the individual dates, but if I bundle them in the years, the sums are calculated incorrectly.
$sql = "SELECT termine.*,YEAR(termine.datummysql) as jahr,COUNT(termin_shopbesuche.berichtstatus) As shopsmitbericht,SUM(termin_shopbesuche.berichtstatus) As summeshops
FROM termine
LEFT JOIN termin_shopbesuche ON termine.__id_termin = termin_shopbesuche._id_termin
WHERE termine._id_asm = ? AND YEAR(termine.datummysql) >= ?
GROUP BY YEAR(termine.datummysql) Order By datummysql";
I've solved it now: I needed a subquery in which I got a 1 or 0 with Case. From this result I group the years.
I've been looking for a solution here in the community, but I have not found anything specific. I need to do searches for birthdays among a period using only the month and month day (excluding year). I have users with their birthdays registered in date fields in my MySQL.
Name | Dt. Birth
Julian | 1990/01/18
Luiz | 2000/02/15
Morgana | 1973/02/01
I need to realize two different tasks.
1st - Let's suppose today date is February 01. How could I take today's date and decrease 14 days, searching for users whose birthday was on previous 2 weeks? (only Julian would be listed).
Another query will list users whose birthday is today (only Morgana would be listed).
And a third one should list the birthdays within next two weeks (only Luiz would be listed)
I was using these code, but they don't seem to work at all times.
select * from user where DAYOFYEAR(dateBirth) between DAYOFYEAR(CURDATE())-14 and DAYOFYEAR(CURDATE())-1;
select * from user where DAYOFYEAR(dateBirth) = DAYOFYEAR(CURDATE());
select * from user where DAYOFYEAR(dateBirth) between DAYOFYEAR(CURDATE())+1 and DAYOFYEAR(CURDATE())+14;
2nd - In a form, I will select two days and months |01||January ||15||February|and the users whose birthday is within this range will be listed. (All users listed)
Maybe this fiddle help you visualize the question. http://www.sqlfiddle.com/#!9/1dec7a/5
I reproduce the above queries that show some inaccuracy. If you change values (-14/+14 and (-1/+1), you shall be able to list the users.
I have an application that records user transactions into a database. The data recorded includes: the time a user performed a transaction (e.g. purchasing materials), the day (e.g. 2016-12-23), what the user transacted, etc. I have an admin panel that collects this data and shows the overall statistics. I need to analyse the data such that, for example; if i need to find out all purchases made for that week (i.e.from Sunday to the current day of the week), i select all appearances from the database that have the dates from the immediate previous Sunday until the current day, so that i show a weekly statistics.
Now, since the average is done weekly, i need only to get the current date, that of the previous sunday and the days in between. I know how to get these two but no idea how to get the middle dates depending on the day of the week.
Note that the time i huse is in the format
$today = date("Y-m-d");
and to get the previous sunday i use:
$prevsunday = date("Y-m-d",strtotime("last Sunday"));
I ask how to get the middle days, and how to handle the updated query.
Any suggestions to improve my query?
Assuming MySQL, you can use dayofweek to figure out "previous sunday":
mysql> select curdate(), dayofweek(curdate()),
curdate() - interval (dayofweek(curdate())-1) day AS sunday;
+------------+----------------------+------------+
| curdate() | dayofweek(curdate()) | sunday |
+------------+----------------------+------------+
| 2016-02-23 | 3 | 2016-02-21 |
+------------+----------------------+------------+
1 row in set (0.00 sec)
So you'd have something like
SELECT ...
...
WHERE dateofpurchase BETWEEN
(curdate() - interval (dayofweek(curdate())-1) day)
AND
curdate();
I'm fairly new to MYSQL and PHP, and i'm working on a project for a security department.
The guards work in 2 teams of 12 hour. (7am - 7pm and 7pm - 7am). They log events that happened during their shift to a database, and now i would like to be able to select only the data from each shift.
I use this for the 7AM - 7PM:
$sql = "SELECT * FROM table WHERE date >'".date("Y-m-d 07:00:00")."' AND date <'".date("Y-m-d 19:00:00")."'";
but I don't seem to be able to find out how I can do the same for the 7pm (previous day) to 7 am.
Most answers I find tell me how to select previous day, but none tells for a specific time during that day.