SSRS - subtract X amount of days from Start/End date using a parameter's input - reporting-services

Title might not be worded the greatest.
Anyway, I have a report and I am trying to set a field where a user can enter an amount of days they want subtracted from today's date.
Ex. The report gets data from July 4 to July 4, if they enter 7 in this parameter, it takes the end date and subtracts 7 from it so they get a week's data.
What is the best way to do this?

Related

Getting the Week Number for the Month Crystal Reports Formula

I have a Crystal Report Grouped by (Day,Week,Month).
I want to be able to display the "Week Number" for the month. Ex: 1st Week Of July, 2nd week of July, 3rd Week of July, etc. on the "Week" Group Header.
I have tried using a Formula
Totext(DatePart("ww", {Command.TransactionDate}),0)
But the result is the "Week Number" for the year EX: 33,34,35. Any help would be very much appreciated
Use an expression like this:
datevar yourDate := currentdate;
Datepart("ww",yourDate)+1
- Datepart("ww",yourDate - Day(yourDate)+1)
of course, replace the variable assignment with your date.
The logic is to get the week number of the date (plus 1) and subtract the week number of the 1st of the current month.

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

Determine if date is before or after the 15th of the month

I have a function which applies a rate based on the number of months that an item has been stored. However we charge half that rate if the item was stored after the 15th. The function I'm using to determine the amount of months an item is stored is the DateDiff() Function. It returns the number of months between two dates. How do I determine if the date is before the 15th or after? If I use DateDiff(d,1/1/2015, 4/1/15) I would get a value greater than 15 so I cannot see if the Date is before or after the 15th using greater than or less than 15. How can I determine if either of the dates (entrance date which is the date the item entered into the storage area and the exit date which is the date it is removed) are before or after the 15th?
VBA models a date as an floating point double. The integral part stands for the day. It advances by 1 per day.
It provides a function Day(date) which you can use to extract the day of the month in which date occurs.
For example, CDate(40000) will return you 6-July-2009, and Day(40000) returns you 6.
I would do something like
if format(date, "DD") <= 15 then
msgbox "this is 15 or below"
else
msgbox "this is 16 and above"
end if
You can put a date variable in instead of date which is a built in function to return the system date.

Repeat table by month from a date range using SSRS

I have here some question regarding on the above subject.
I have a parameter which is Start Date (01/01/2013)
and End Date (03/31/2013)
and a table which displays the data.
Here is my question
Can I repeat the table by month?
so if my date range is 01/01/2013 to 03/31/2013
I should have 3 tables for January - February - March
Is this possible?
Use a List control, grouped on Month Name or Month Number (or anything to designate a month), put a table within the List control to house your data for each month.

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.