I have a date field on which my inventory item was bought. Then I have a lifespan field in months eg 240. Now I am trying to calculate the end of the item's lifespan date but I get an error:
numbervar myVariable := ({TABLE.LIFESPAN} * 30);
dateadd("d", myVariable,{#date})
I get the following error: "Date must be between year 1 and 9999"
As soon as I change the variable to: numbervar myVariable := {TABLE.LIFESPAN};
it works without any errors. Also if I change the dateadd formula to dateadd("d", 7200,{#date}) it works.
The format of the field TABLE.LIFESPAN is decimal(9,2) but none of the value has decimals, eg it will be 240.00
I have also tried
numbervar myVariable := Round({TABLE.LIFESPAN} * 30);
I suspect it has something to do with the decimals.
Help will be greatly appreciated.
you will receive this value once your ({TABLE.LIFESPAN} * 40) causes the year to be greater than 9999. So if {#date} were today's date then {TABLE.LIFESPAN} could not be higher than 73955 or so. I would create a formula for ({TABLE.LIFESPAN} *40) and drop it on the canvas and see what that value is on all records and see if you have an unusually high number somewhere.
Related
I'm creating this report in spreadsheet
https://docs.google.com/spreadsheets/d/1U48MybVshKT3eRYE9goRCab9k1KCoXe7Zsr9Ogkkm4Y/edit?usp=sharing
In "BD" you can find the records and in "NB-month" the KPI that I want to analyze; I would like to create DATE filter for the numbers in the columns, ex for the col: "nº Contract closed" I'm thinking to use this formula:
=COUNTIFS(BD!R:R;A5;BD!G:G;">"&DATE(B2))
but I get a value: "0" that is incorrect because for this agent "Carla Vaello" the number of contracts closed after 2020-02-01 should be "2".
your usage of DATE formula is wrong (DATE requires 3 parameters). either change DATE to DATEVALUE or use:
=COUNTIFS(BD!R:R; A5; BD!G:G; ">"&B2)
I have the following mysqli query in my search.php file with ajax.
SELECT demand2.* FROM demand2
WHERE ddate >= '$dto' AND ddate >= '$dfrom' AND !(mach='--' OR mach='-' OR mach='' OR mach='----' OR mach='-----' OR mach='---');
field ddate is datatype of varchar2
as I entered Date From 01-01-2019 and Date To 30-01-2019, it shows the result with previous date like 29-12-2019.
So I can't find the solution to get result within specified range. Please Help.
Just as rypskar said, your type of field should be date.
If you don't want to change the datatype of the fiels, then you have to convert the string to date with STR_TO_DATE(ddate, '%d-%m-%Y'). But this is not recommended, as it will cause performance degradation on larger tables.
So your query would be like that (not tested!):
SELECT demand2.* FROM demand2
WHERE STR_TO_DATE(ddate, '%d-%m-%Y') >= STR_TO_DATE('$dto', '%d-%m-%Y') AND STR_TO_DATE(ddate, '%d-%m-%Y') >= STR_TO_DATE('$dfrom', '%d-%m-%Y') AND !(mach='--' OR mach='-' OR mach='' OR mach='----' OR mach='-----' OR mach='---');
If you want to keep the varchar type of field and not make any runtime conversions, then you have to change the format to Y-m-d, so the comparison with character set will work the same as a date comparison.
Right now, you are getting the result of 29-12-2019 because 29 is between 1 and 30.
Now, I have successfully display the time in "HH:mm" format, but I will need to change it to decimals. For example, the hours is 2.30 meaning 2 hours and 30 minutes, but I need it to be 2.5 meaning 2.5 hours. Please help. Below is my code:
Local NumberVar HoursDiff;
Local NumberVar MinutesDiff;
Local NumberVar SecondsDiff;
Local StringVar strOut;
SecondsDiff := DateDiff('s',{Invoicing.TimeFrom},{Invoicing.TimeTo});
HoursDiff:= SecondsDiff \ (60 * 60);
SecondsDiff := SecondsDiff MOD (60 * 60);
MinutesDiff:= SecondsDiff \ 60;
strOut := strOut & CStr(HoursDiff,0)& '.' & CStr(MinutesDiff,'00');
strOut
Try the following formula, I think it will work for you
timeVar time_value := CTime("2:30");//Time in HH:mm format
stringVar timeString := ToText(time_value);
numberVar time_in_min := ToNumber(Split(timeString,":")[1])*60 + ToNumber(Split(timeString,":")[2]) ;
time_in_min/60;
Convert this returned string value to time format using "time(strout)", then right click on formula field then select format filed option, it will opens a format editor in this select "date and time" tab. Then click on "customize" tab it will opens a custom style window.
in custom style window select time from order field in "Datetime" tab. then click on time tab and select which format you want.
My client has a report that accepts a date range to get a report showing projected revenue. So, a user would enter a date range of '1/1/2015 to 1/31/2015' and the report should return data only in the range '1/1/2015 to 1/31/2015 grouped by week. I am instead for the week of 12/29/2014 (which 1/1/2015 fall into) and 2/1/2015 (which 1/31/2015 falls into). The report is intended to group by week, but I do not want days on the report that are earlier than the start date parameter or later than the end date parameter.
The sql statement for this report is:
SELECT job.job, job.status, job.customer_po, job.part_number, job.unit_price,
job.price_uofm, delivery.promiseddate, delivery.remaining_quantity, job.build_to_stock, job.description, job.make_quantity, job.pick_quantity, job.shipped_quantity, job.lead_days
FROM dbo.delivery as delivery RIGHT OUTER JOIN db.job as job on delivery.job = job.job
WHERE job.build_to_stock = 0 AND (job.status = 'active' OR job.status = 'hold' OR job.status = 'pending')
The date range is from this code and parameters:
Max – Maximum(?Date Range)
Min – Minimun(?Date Range)
Date Range - "From " & {#Min} & " to " & {#Max}
This is the group expression
Group 2 Name - GroupName ({#Adj Date 2}, "weekly") & " thru " & cdate(GroupName ({#Adj Date 2}, "weekly"))+6
This is the select expression
{#Date} = {?Date Range} and
not {Job.Build_To_Stock} and
{Job.Status} in ["Active", "Hold", "Pending"]
Do you know how I can prevent the "overflow" of dates outside of date range?
Thx
As long as you have date filtering in your record selection formula there will not be any "overflow" outside of that range. If you've got {Record.Date} in Minimum({?DateRange}) to Maximum({?DateRange}), which it sounds like you do, then your report will not contain any records outside of the parameter regardless of how you group them.
Your problem might stem from over-complicating or misinterpreting the grouping. All you need to do is group by {Record.Date} and select "Group by week" in the grouping options... you don't need any complicated formulas to break it out by week. But be aware that the way weeks are referred to is by their starting date. For example, if you had a record with a date of Feb. 19, 2015, that record would fall into the group labeled "Feb. 15, 2015" even if your {?DateRange} parameter was Feb. 18 - Feb. 15.
I am using Crystal Reports XI R2.
My table has transaction data by date. I have a group set up by day and a summary to give a count of transactions for each day. I also have a running total set to give a year to date count for each day. Of course it resets on a change in year.
My goal is to be able to find the difference between the YTD count yesterday and the same for the same date last year.
Edit: I've misstated the goal. It isn't to be able to find the difference for just yesterday, but for each day in a range of days.
Create these two formula fields:
//{#LastYearToDate}
If {table.dateField} IN LastYearYTD Then
1
Else
0
//{#ThisYearToDate}
If {table.dateField} IN YearToDate Then
1
Else
0
Insert a summary on each field in the ReportFooter section.
I finally got this nailed down. There is likely a cleaner way of doing this, but....
I converted the dates (started as text yyyy-mm-dd) into text mm/dd/yyyy format:
stringvar yyyyear := {table.dateField}[1 to 4];
stringvar mmonth := {table.dateField}[6 to 7];;
stringvar dday := {table.dateField}[9 to 10];
mmonth + "/" + dday + "/" + yyyyear
Grouped by this field and inserted a count summary into the group header. Created a separate field for the mm/dd portion of each date:
{#textDate}[1 to 5]
Added a flag to see if the date in the current group header matched the previous:
if previous({#mm/dd}) = {#mm/dd}
then 1
else 0
Used a shared variable to store the YTD totals for each year (2 formulas):
shared numbervar totalsCurentYear;
if {#prevDateFlag} = 1 then
totalsCurrentYear := totalsCurrentYear + Sum ({#transactionCount}, {#textDate});
totalsCurrentYear
|
shared numbervar totalsLastYear;
if {#prevDateFlag} = 1 then
totalsLastYear := totalsLastYear + Sum ({#transactionCount}, {#textDate});
totalsLastYear
Put both of these into the group footer (suppressed) and added a field to do the subtraction into the group header.