Report Builder 3.0 Date Prompt + / - 14 days - reportbuilder3.0

I have a report where the users selects the date in the prompt. I need to change the code so the report selects data 14 days before and 14 days after the selected date.
This is why I currently have and it runs:
cast(pymt_dt as date format 'MM/DD/YYYY') = ?
I'm trying to change it to between but it throws an error message when it runs. This is what I changed it to:
cast(pymt_dt as date format 'MM/DD/YYYY') between (? - 14) and (? + 14)
I'm sure the syntax is wrong but not sure how to correct it. The question marks represent the value from the date prompt. The Date Prompt value is date / time.
Thanks for the help....

I would use DateAdd(). So where you have (? - 14) and (? + 14) it'd be DateAdd(d, -14, ?) And DateAdd(d, 14, ?)
DateAdd() pretty self explanatory - the first parameter defines an interval, the second the amount of interval you want to add and the last the date you want to add it to, so this is add 14/-14 days to ?
Hope that helps.

Related

How to search inside of a LookupSet

If you do a LookupSet and it returns the values:
11/6/2014 3/17/2015 9/14/2015 2/27/2013
is there anyway to search those dates and return only the dates that meet certain criteria, such as year = 2015 and Month >= 7
Here is the code that gave me the above values:
Join(LookupSet(Fields!UNID.Value,Fields!Parent_UNID.Value,Fields!Inspection_Date.Value, "Inspections"))
Only way I can think of doing this is an Iif() to change the date into something conspicuous and then a replace to delete them:
=Join(LookUpSet(Fields!UNID.Value, Fields!Parent_UNID.Value, Replace(Iif(Year(Fields!Inspection_Date.Value) = 2015 And Month(Fields!Inspection_Date.Value) >= 7, Fields!Inspection_Date.Value, "XXYYZZ"), "XXYYZZ", Nothing), "Inspections")
So what this does is checks if the Year of the date is 2015 and the month is >= 7 and if so, returns the date. If it's not, it returns XXYYZZ, and then the Replace() statement looks for that string and just returns it to nothing.

Year, Month, and Day parameters describe an un-representable DateTime Exception

I'm adding an object to a list within an ASP.NET MVC 3 application using the following code but one of the properties of the object is giving me difficulties.
ls.Add(new UserRoleModel { UserRoleId = 1, UserName = "Paul", InsertDate = new DateTime(05, 24, 2012),InsertProgram="sqlplus",InsertUser="sp22",Role="Implementation Co-corindator"});
This builds but when I go to the relevant page i get an Exception with the following type:
Exception Details: System.ArgumentOutOfRangeException: Year, Month, and Day parameters describe an un-representable DateTime.
I've tried removing the 0 in the month but I get the same exception.
The DateTime constructor you are calling accepts parameters in the order year, month, day.
You are providing them in the order month, day, year -- which ends up trying to assign meaningless values. The documentation is pretty clear on what the allowed values are and what happens if you pass 2012 for the "day" value.
I just ran into this and my issue was I was creating a date in February. I tried to do the following...
new Date(2013, 2, 30)
Since there is not a February 30th, the date failed to create. When I changed to
new Date(2013, 2, 28)
it worked fine.
if the InsertDate meant to be the date / time of creation you can just use the following
DateTime InsertDate = DateTime.Now;
You are using an Invalid datetime, like for month you may be passing 13,14 days more than 31
or something like that which is causing the issue.
i was having the same issue because i was trying to create a DateTime object with date set to 31 of April even though April only has 30 days.
Anyone having the same issue, make sure you are not making this mistake.
Simply you have to change the InsertDate into
InsertDate = new DateTime(Year,Month,Date);
It will solve your problem.
I was facing the same type of issue, where I was using a DateTimePicker in Winform Application. Where user can only pick only month and year and my code and UI was look like
Code
this.dtpMonth.CustomFormat = "MMMM yyyy";
this.dtpMonth.Font = new System.Drawing.Font("Verdana", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.dtpMonth.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
this.dtpMonth.Location = new System.Drawing.Point(88, 24);
this.dtpMonth.Name = "dtpMonth";
this.dtpMonth.ShowUpDown = true;
this.dtpMonth.Size = new System.Drawing.Size(136, 22);
this.dtpMonth.TabIndex = 1;
And I was initializing the by this.dtpMonth=DateTime.Today; and this line cost me and error of current discussion.
Afterward, I have found that my date(DateTime.Today) was 31 July. So, when user want change the month to August it throws exception because August doesn't have date 31. Finally, I change my code into
dtpMonth.Value =new DateTime(DateTime.Today.Year, DateTime.Today.Month,1);
And worked for me.
The same exception I solved as:
DateTimePicker1.Value = DateSerial(Year(Now), Month(Now) + 1, 1)
For those who has this issue, make sure that date, which you try to create exists. For example, I had this problem, because was trying to create 29 feb at not leap year
if you got this error because you're trying to insert 29 days in a year that's not a leap year, then you can check the maximum allowed days first of that year as such:
if(DateTime.DaysInMonth(2024,2) == 29)
dt = new DateTime(2024, 2, 29);

Convert DDMON (eg. 23JAN) date format to full date with correct year applied in Ruby

Am looking for a compact solution for converting the dates that come from the airline reservation systems (GDS like Sabre/Galileo/Amadeus) which dont have the year - eg. 23JUN to a standard date, but need to determine the year quickly to tack on in Ruby. (FYI - on these systems date can only be max 355 days from today. So there is no ambiguity of interpreting 12MAY as 2013-05-12 instead of 2012-05-12 assuming today is 12MAY 2012). If today is 25th Dec 2012, and date is entered as 01JAN, this would be 01JAN2013 in the future, and if today is 21JUL 2012, input date of 01JAN would also become 01JAN 2013 as it is a past date in the current year.
So I can do something like:
t = DateTime.now
crsdate = DateTime.strptime("23JAN","%d%b")
if crsdate >= t
# Year is current year
else
# Year is next year
end
Is there a more elegant way of doing this?
How about this?
t = DateTime.now
crsdate = DateTime.strptime("23JAN","%d%b")
crsdate >= t ? crsdate >>= 12 : crsdate
If you don't need to modify crsdate because you just want to return this, use >> instead of >>=.

Oracle DateAdd() of 2 different columns

I'm trying to figure out a DateAdd() equivalent in Oracle that is actually the difference in seconds between 2 columns in the same table:
SELECT
DISTINCT p.packet_id,
p.launch_dt,
r.route_duration,
s.completion_date,
DATEADD(SS, r.route_duration, p.launch_dt) AS tempDate
FROM
tdc_arc_apprpkt_def p
JOIN tdc_arc_inpr_route_def r
ON p.packet_id = r.packet_id
JOIN tdc_arc_inpr_route_step_detai s
ON p.packet_id = s.packet_id
AND s.completion_date > DATEADD(SS, r.route_duration, p.launch_dt)
Any help would be greatly appreciated!
In addition to being able to do date arithmetic using fractions of days as Tony demonstrates, assuming you are using 9i or later, you can also use interval functions (or, even better, define the ROUTE_DURATION column as an interval) and add intervals to dates. In your case, you can do
p.launch_dt + numtodsinterval( r.route_duration, 'SECOND' )
to add route_duration seconds to launch_dt.
If you were to define the route_duration column as an INTERVAL DAY TO SECOND rather than a NUMBER, you could simply add it to a date
p.launch_dt + r.route_duration
If I understand you correctly, you want to add r.route_duration seconds to p.launch_dt? In that case the expression is:
p.launch_dt + (r.route_duration/24/60/60)
Oracle DATE arithmetic works in days, so the divisions by 24, 60 and 60 convert the route_duration value from seconds to days.

How do I dynamically select parameter with crystal report

I have been working on getting a report out for long without success.
I have a report that select based on parameter fields of date and boolean. Currently I have to create 3 reports. One based on dates, one based on the boolean and one based on both.
However, I want my report to be able to select all dates if the user does not input date in the parameter or select all booleans if user does not select one.
Currently I used this
if ({?Start Date} = DateTimeValue('') or {?End Date} =DateTimeValue('')) then
{rectReport.Call date} in DateTimeValue ('1753-01-01 00:00:00') to CurrentDateTime
else
({rectReport.Call date} in {?Start Date} to {?End Date}) and {rectReport.EngineDown} = {?Engine Down}
The basic Idea I am looking for is that the user can decide to select only one parameter instead of the two.
Any help will be highly appreciated.
Thanks,
Bimbo
In Crystal 2008 you have the option of making parameters optional. What you could do is create one report with both parameters and then set both parameters as optional. In your record selection formula you could do something like this:
(if (HasValue({?Startdate}) and HasValue({?Enddate}))
then {table.datefield} in {?Startdate} to {?Enddate}
else {table.datefield} in {defaultstartdate} to {defaultenddate})
and (if HasValue({?BoolParam}) then {table.boolfield} = {?BoolParam}
else {table.boolfield} = {defaultbool})
If you wanted to select ALL tables if the user did not input the parameter, you could just omit the else-statements.
(note: Sorry if that syntax isn't correct (I am just getting back into CR again), but you get the idea.)
EDIT: Since optional parameters aren't available in CR10, couldn't you just use parameter default values for the dates instead? For the boolean, you could just make a parameter with 3 values: true, false, and "all" and then default to the "all" value when running the report.
I don't know your particular situation, but the way we handle this (specifically for Defined Periods vs User-specified-Date-Range) is through being able to set defaults.
Our main environment is BOE XI.
Our parameters might be
ReportPeriod (String Variable)
and
CustomDates (DateTime Range, but will work as two discrete dates)
Example params for ReportPeriod might be
1 Day
7 Days
Last Month
Custom Dates
Formulas are used to calculate date limits that will be used in the record selection. I start with the END DATE, as it is convenient for our period reports.
#EndDate
Select ?ReportPeriod
Case
"1 Day", "7 Days" : CurrentDate
// Conveniently defaults to MIDNIGHT
"Last Month" : Maximum(LastFullMonth)
"CustomDates" : Maximum(?CustomDates)
// Or discrete parameter for end date
default : CurrentDate
#BeginDate
Select ?ReportPeriod
Case
"1 Day" : DateAdd("d", -1, #EndDate)
"7 Days" : DateAdd("d", -7, #EndDate)
"Last Month" : Minimum(LastFullMonth)
"CustomDates" : Minimum(?CustomDates)
// Or discrete parameter for end date
default : DateAdd("d", -1, #EndDate)
And, let me caution against using CurentDateTime unless necessary. Every time you try to step through the report, the selection will have changed: 5:01:10 PM ... 5:01:16 PM ... 5:01:24 PM ...
When publishing a report, we set default date (it doesn't matter what, it's only used for CUSTOM and the customer resets it then), and a default ReportPeriod.
The report can be scheduled periodically (based on ReportPeriod) and it will always run.
If the user wants to do custom dates (historic reporting, etc.), then they can chose that for report period, and then set whatever start and end dates they need.
Helpful?

Resources