Dates criteria for dates 11 to 12 months previous to todays date - ms-access

I'm making a query that needs to show dates for members that signed up between 11 months and a year ago from todays date so that the user can tell what members need to renew their membership and I'm not sure how to accomplish this in the criteria area

For full months, that could be:
Where DateDiff("m", [SignUpDate], Date()) Between 11 And 12
If you need per the exact date, it takes some more:
Calculate Full Months Between Two Dates in MS ACCESS Query
Using that function, the criteria will be:
Where Months([SignUpDate], Date()) Between 11 And 12

Related

Is there a way for me to get the previous 3 months of data, but for every row? SQL

I want to create a table that has two columns, date and count.
Date is basically just date since we started accepting payment until today (let's say 2021-09-01 to today).
Count represents the # of active merchants (i.e. anyone that has processed ANY transaction in the past 3 months)
I understand that in order to get the last 3 months of data from today, I need to do
created between date_add ('month', -3, current_date) and current_date
Is there a way that I can do that for every single row, so instead of using current_date, I can use the date that is in the date column?

MySQL-Get latest data of 1st 4 days of current month

I have a table in my database which stores the meters energy value of 1st of every month. In case meter is offline it will store the value of the next day.
Below is my case
I have a record of a meter of past 2 months February and March. The February data is of 2019-02-01 00:00:00 but there are 4 rows for the month March. See the below image
In the above image the 1st,2nd and 3rd of March have a null value of FA but the 4th March contains some value.
What I have done?
I am able to select the rows having values of FA.
What I want to do?
I want to get only the current month data i.e. Current month is March so it should get only march record and then next month it should get only April record and so on.
The query should not exceed the days limit more than 4 i.e. It should only check record for 1st four days of every month.
Here is my DB-Fiddle
Any help would be highly appreciated.
one way to solve this is
FOR
I want to get only the current month data i.e. Current month is March so it should get only march record and then next month it should get only April record and so on.
means month(TV)= month(now())
and
The query should not exceed the days limit more than 4 i.e. It should only check record for 1st four days of every month. means day(TV)<= 4
and finally your query
select * from `biz_pub_data_f_energy_m` a
where a.`DATA_ID` = '1b9716122dd5408691a063227316ac0a'
and a.`FA` is NOT NULL and month(TV)= month(now())
and day(TV)<= 4
You can try below -
DEMO
select * from `biz_pub_data_f_energy_m` a
where a.`DATA_ID` = '1b9716122dd5408691a063227316ac0a'
and a.`FA` is NOT NULL and tv>=date(DATE_SUB(now(),INTERVAL DAYOFMONTH(now())-1 DAY))
and tv<=DATE_ADD(date(DATE_SUB(now(),INTERVAL DAYOFMONTH(now())-1 DAY)), INTERVAL 4 DAY)

date calculation with full date in separate columns

I'm trying to make a query for the last 3 months of an item with my month and year in separate columns like so:
YEAR_ PERIOD
2014 5
2013 6
2013 11
2011 6
2009 2
The query needs to always start from the current month and year. I've tried using DateAdd(), DateSerial(), and DateDiff() none of those worked. Whenever I try to use month(now()-3) i'm getting 2 instead of 11.
Adding or subtracting integers and dates simply adds or subtracts days from the date. So Now() - 3 results in 2016-02-15 (it is 2016-02-18 at the time of this posting). That is clearly still the month of February - hence your result of two.
Give this a try Month(DateAdd("m", -3, Now)). Here we are adding -3 months to the current date and then getting the resulting month. Based on today's date that will result in 11.
I figured it out.
DateDiff("m",CDate(Format([PERIOD] & "/" & [YEAR_],"mm/yyyy")),Now())
This took the two fields and made them a single date. I then took the difference from this month and the months between the two dates. I then set the criteria to <= 3.
Addendum
It can be simplified to:
DateDiff("m",CDate([PERIOD] & "/" & [YEAR_]),Date())
In general, however, you should never use string handling for dates if it can be avoided, and it easily can:
DateDiff("m",DateSerial([YEAR_],[PERIOD],1)),Date())

selecting recurring dates in a date range that may or may not have a year

I have a table of users with various dates like birthday, date of hire, and annual review date. The birthday may or may not have a year, the date of hire does have a year, and the review date does not have a year.
I want to be return a query across a date range that returns the rows with the dates calculated for the year of the date range for these recurring events.
For example:
A user with the following:
dob:1980-05-05
doh:2005-06-22
review:0000-10-01
Then if I query for a range of say, 2012-05-01 to 2013-12-01 I'd like it to return records like:
Event,Date
dob,2012-05-05
doh,2012-06-22
review,2012-10-01
dob,2013-05-05
doh,2013-06-22
review:2013-10-01
I realize that this probably will be done in separate UNION queries on each date field which is fine. This isn't exactly the same problem as finding dates x days in the future as I need the recurring date with the proper year in the given date range which may be over multiple years if the range is large enough.
I can only think of doing this programatically. First checking if the start and end range span over a year. Then split the dates into start date to end of year, start of year to end date etc. and run a query for each span.

MySQL selecting date range but also between

My db is made of groups of entries (by user) with a row for each day of the week and also groups where there is only 1 row per week of the year. This week may start Sat, Sun or Mon.
The sql groups all these rows by user id and works fine for the entries where the user has a row for every day
The problem I have is selecting the users rows where there is only one entry per week
Basically if the rows date is 11th Feb 2012 then I need to be able to select that row if the start date criteria falls on that date or within that following week and all rows upto but not including the row where the date column is after the end date
I'm trying everything like dateadd in the sql but I just cannot get it to add these rows in.
Hope I've made myself clear.
Say I have two entries in the db
2013-02-02
2013-02-09
I have a start date of 2013-02-05 and an end date of 2012-02-13
I need to get those two row as:
the start date falls on or within the week of 2013-02-02
and I also need 2013-02-09 as the end date falls on or within the week of that date.
Hope that makes it a bit clearer.
Not sure exactly what your question is asking.
If your field is of mysql date or datetime type, and you wanted to find if there was an entry for a given week could you not use MySQL WEEK Function to find all entries for the given week, you may also need to include a restriction on YEAR too.
You could also include the following week, but you may encounter problems. The main problem being week 52+1 of 2012 wont give week 1 of 2013, but week 1 of 2012.