ms access annual criteria - ms-access

I need to create a query criteria to get any date from the last 1 may of last year till today, example if I run the query now it should get the data from 1 may 2012 till today, if I run the query the next year on Feb 2013 then get the data from 1 May 2012 till feb 2013.
update
I have used the below as the [JOINED DATE] query criteria but it returns nothing, what is wrong with this?
IIf(Month([Data]![JOINED DATE])>=5,Between DateSerial(Year(Now()),5,1) And Now(),Between DateSerial(Year(Now())-1,5,1) And Now())

Your syntax is incorrect, I do not advise including the "between" keyword in the IIF statement, you want your IIF to only return the date, something like:
SELECT *
FROM A
WHERE A.Date BETWEEN IIf(Month([Joined Date])>=5,DateSerial(Year(Date()),5,1),DateSerial(Year(Date())-1,5,1) AND Date()
Note: I have used Date() rather than Now() as Now() includes the timestamp which is not necessary in this case.

Related

Selecting records assuming future dates in mysql

I used the following select statement to select sum of amount assuming no future dates. How do I change this statement to include future dates?
SELECT SUM(amount) as allPreviousAmount
FROM `fn_table`
WHERE MONTH(transdate) < ? OR YEAR(transdate) < 2019 )
The ? is representing the month number. I have data in 2018, 2019 and 2020. Now I want to select all data before February 2019. How do I select it? The problem is that this also select data in 2020.
Regards your existing query, surely you'd need AND, not OR, to ensure no future dates? Say it's July 2020 and you have a date of January 2021 which is in the future. If you say MONTH('jan-2021') < MONTH('jul-2020') OR YEAR('jan-2021') < YEAR('jul-2020') then this will be true because jan is earlier than jul so a future date of January 2021 will be returned
Not really sure why you didn't just WHERE transdate < CURRENT_DATE() unless a any day this month is also classed as a future date... (by demanding the the month and the year have to be less than the current date, if it's 13th July 2020 you'll only get records up to end of June 2020 if you consider month and year only)
But to include all dates past and future simply remove the WHERE clause entirely
Edit in response to comment:
If you want a query that gives "all data up to but not including 01 Jul 2005" then do:
WHERE transdate < ?
And in your front end supply a date type parameter of 01-jul-2005. Any date can be supplied, but to cut off at a particular month end, supply a date that is the first day of some month
You can reuse the same query for future dates too by providing a date higher than any possible date in the table, such as 01-jan-3000

SSRS Returning incorrect WW

I have an SSRS report (2008R2 3.0) that uses parameter filters for workweek in the format YYYYWW. In 2018 there were 52 work weeks based on the ISO standard (source) .
For default parameter value I select the last WW using the following formula:
DATEPART(DateInterval.Year, DATEADD("d", -7, now())) & FORMAT(DATEPART(DateInterval.WeekOfYear, DATEADD("d", -7, now())), "00")
For some odd reason this returned 201853. From what I understand it should be 201852 given the date when ran was 20180106.
I know in T-SQL I can define return type using ISO_WEEK but is there an equivalent for DateInterval in SSRS?
To simplify:
DATEPART(DateInterval.WeekOfYear, DATEADD("d",-7,now()))
Returns 53 instead of 52 when ran from 201801-201807.
Any idea as to why this is returning the wrong WeekOfYear value?
I think this may be due to your Regional First Day of the Week setting on your server.
If your First Day of the Week is Saturday, there are 53 weeks in the 2018. You can set the first day of the week with the DATEFIRST setting in SQL Server.
Use SELECT ##DATEFIRST to determine your servers setting.
This example code will show the difference.
SET DATEFIRST 7
SELECT ##DATEFIRST
SELECT DATEPART(WEEK, '2018-12-30')
SET DATEFIRST 1
SELECT ##DATEFIRST
SELECT DATEPART(WEEK, '2018-12-30')
For your query, you may need to set the first day of the week to Sunday with SET DATEFIRST 1.
MS Docs: DATEFIRST

Mysql query to fetch/store records in a specific month

I have this module where i am supposed to check the winners of bidding in the current month. be that October, November, December or whatever.
I run this query,
SELECT *
FROM auction_winners
WHERE MONTH('2015-10-16 00:00:00')
but it shows me everything, from all the months.
i believe even if this query works it will work for October only, i am looking for something that checks system current date month.
Just add your column with date:
SELECT * FROM auction_winners WHERE MONTH(column_name) = MONTH('2015-10-16 00:00:00')
or:
SELECT * FROM auction_winners WHERE MONTH(column_name) = MONTH(NOW())

sql search between date Error

I want to retrieve data between two specific date and I am getting that perfectly right with this query
select * from POS.dbo.voucher where date_time between '10 october 2014 00.00.00 ' and '11 october 2014 12.00.00'
but the issue is if I'm changing the month something like
select * from POS.dbo.voucher where date_time between '10 march 2014 00.00.00 ' and '11 march 2014 12.00.00'
It's still returning me with the same records. Seems like its only comparing the date and returning me the records.
Any idea where i m doing it wrong?
I am taking date as varchar in database.
Thanks!!
You appear to be using SQL Server (based on the dbo). Use a standard date format for date constants:
select *
from POS.dbo.voucher
where date_time between '2014-10-10 00:00:00' and '2014-10-11 12:00:00'
However, for this to work, you need to store dates using proper date formats in the database. So, you should fix the data structure to store dates using the correct data type.
I agree you would be better off changing the field from varchar to datetime. If that's not an option then you should convert the varchar field in the query into a datetime as appropriate in MS SQL Server, probably through a function, perhaps through a cast. BTW, best to tag with actually db used, and maybe SQL too.

Datediff function adds startdate day also to the output

I have a report in Report Builder 1.0 wherein I have written a formula that calculates the number of days between startdate and enddate. For that I have used a DATEDIFF function in such a manner:
DATEDIFF(DAY, TODAY(), column from table which has end date)
Suppose, if today's date is 1 July 2013 & the column is sending end date as 10 July 2013, then the DATEDIFF function is returning "10 days" whereas it should return output as value "9 days". Why is it returning 10 days rather than 9?
Execute this in Sql Server and you get 9 days:
select DATEDIFF(day, '2013-07-01', '2013-07-10')
Using this as a dataset:
select CAST('2013-07-01' AS DateTime) AS StartDate, CAST('2013-07-10 23:59:59' AS DateTime) AS EndDate
then using this expression in SSRS:
=DateDiff(DateInterval.Day, Fields!StartDate.Value, Fields!EndDate.Value)
still yields 9 days, even when using a time component. Try the following expression:
=DateDiff(DateInterval.Day, DateTime.Today, Fields!EndDate.Value)
Are you displaying the date fields to make sure what you think you should get is what you actually get? For instance, make sure you aren't being returned cached data.