How to search birthdays dates using only day and month - php

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.

Related

MySQL reminder notification one month before expiration date (6 months)

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)"

Add MySQL date (month-day) that accounts for every year

I'm making a web app in PHP that calculates vacations and some are fixed, say for example, Christmas, so instead of adding dates like
2015-12-25
2016-12-25
2017-12-25
2018-12-25
Is there any way to add something like
*-12-25
That accounts for every 25th of December of ALL the years? I know PHP has this but since I'm getting the dates from a Vacation Dates table that is populated by the admin I can't figure out how to do this in PHP, else I'll have to default to add 10 years to each entered date

Best way to count and group blog-like results

We have a database of news posts on our site that has some 3000 rows (one for each post, dating back to 2001). Each has a unix timestamp indicating it's post date.
I want to have an archive page that shows a summary of how many posts were on that given month. So grouped by year, then month
2011
January (13 posts)
February (25 posts)
2012
March (30 posts)
etc.
What's the most efficient way of doing this? I had a mess of code before that had two for loops (year, then month) which would query the database for each month and count how many posts were made then. It was, not surprisingly, incredibly slow.
Any tips on how to group the data and avoid hitting the database for every single month.
This is best handled with a aggregated table in the database for keeping statistics on a monthly basis. You can have a simple table with 3 columns.
Year | Month | Count
on a daily basis you run a simple aggregated query counting the number of posts for that month (using a filter) and update the table above. It will be fast and clean.

scheduling php mysql db design

We are trying to design a program that will allow users to book tutors based on tutors' availability. So we want tutors to tell us when (what time, day, etc) they are available/not available, and when a user books a specific day and time, we only want to show that user the tutors that are available for that particular day and time.
For example, tutors could tell us they are available M-W from 9-5PM.
How could I design such a table?
I was thinking of doing the followin
non-availability:
(this allows tutors to tell me they are not available on a specific date ... say 4/15/2012 10PM)
date date
time_start datetime
time_end datetime
recurring_non-availability
(this allows tutors to tell me that they are not available every Monday from 9-5pm)
dayOfWeek enum
time_start
time_end
So basically, tutors can specify for each day of the week, the times they are not available. They can also specify specific dates they are not available. If a user wants a tutor for a specific date like 4/20 10AM, I will first query the non-availability table to make sure there are no conflicts for 4/20 10 AM, and then query the recurring_non_availability table to make sure they are no conflicts for Friday (4/20 is on a Friday) 10 AM. I am not sure if this design will give me the best picture of a tutor's availability.
Perhaps set up a table with all the days of the week tutors will be available and then have the times they are stored within like so?
Tutor monday tuesday wednesday thursday friday
bob 9-5 9-5 9-5 10-3 9-12

Need to store multiple date range values and retrieve them via sql

I'm building a home rental system. The system stores profiles of homes and users can book homes for rent for periods as between one day to a year. I've got the booking part all set up except I am faced with a requirement from teh client to be able to set certain dates and date ranges as un bookable for homes.
A home can be available for a whole year for rent, or can be available for 6 months, or be unavailable on discreet days eg: Holidays and weekends for summer homes etc.
I'm perplexed as how would I be able to set up a database table to store this information considering that the information must be retrievable by a sql query. I mean consider the following situation, a home can be rented through out the year except on wednesdays, the 4th of July, 10 November to 25th December and 31st December.
How do I store this in a database and be able to run a query to check for a homes availability between set dates. I'm wokring in php MySql
There are two different concepts that you're describing: the "on Wednesdays" is not as much of a date range as it is a recurrence pattern. The same goes for "weekends".
You're probably looking at two different tables in addition to your property table that define these unavailable dates: one that represents specific date ranges and one that represents recurrence patterns.
Property
|
-------------- ---------------
| |
PropertyUnavailableRecurrence PropertyUnavailableRange
(Bear in mind that you might want to figure out shorter names)
PropertyUnavailableRecurrence would need to store the information necessary for turning "Wednesdays" and "weekends" into viable decision logic. I can't model this for you, since all of you've presented in this pattern are specific days of the week, but I'd imagine that you'd need to be able to account for "First of the month" or "Second Wednesday of the month", but I don't know. In any case, this is where you'd need to store that information.
PropertyUnavailableRange would just contain simple From and To dates that define the range. This part is pretty simple.
Of course, an alternative would be to take the recurrence patterns specified in the application and turn them into discreet PropertyUnavailableRange records, but you'd still need to set up a table to store these recurrences and associate the discreet records with a recurrence so that you could manage them.
One approach is to have a table, PropertyUnavailable, with the following structure:
create table PropertyUnavailable
(
property_id number not null,
when date not null
);
This table would have a row for each day that the property is not available because of a black out period (e.g., every Wednesday, Holiday, etc). I am ignoring how you will store the meta information of the pattern -- all this table wants are rows for each day where the property is not available because of a blackout period.
I assume you will also have a table for reservation days, PropertyReserved, with the same structure as above plus a foreign key to reservation_id (or something similar).
Now to see what day's are unavailable/reserved for a given date range, the sql would be something like this:
SELECT a.when, 'blackout'
FROM PropertyUnavailable a
WHERE a.when between <from_date> to <to_date>
UNION ALL (
SELECT b.when, 'reserved'
FROM PropertyReserved b
WHERE b.when between <from_date> to <to_date>
);
If nothing is returned with the query, then the property is available between the date range specified (from_date, to_date).
Did you consider simply booking those "unbookable" dates in the name of the system?
It appears that you are not clear about what is required to be stored in teh database; and what is required in code segments. Set the "unbookable" dates aside for a moment, assume you only have actual booked dates. Catcall has a point. What does your current code look like, when you search for available dates ?
SQL is quite capable of handling dates and performing date arithmetic. My NonSQL is not, you will have to store more in the databse than in real SQL. But you do not need to store rows per date. The Reservation table needs FromDate and ToDate only.

Categories