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.
Hi I'm new in crystal reporting, i would like to make percentage for annual year growth based current year with the previous year.
For example, I would like to check the growth for CMP4 for current year (2017) and previous year (2016).
CMP_vc_Code,InvYear,Jan,Feb,Mar,Apr,May,June,July,Aug,Sep,Oct,Nov,Dec
CMP1,2016,0,0,318.50,68.25,91,182,338,195.25,140.70,0,117.25,0
CMP2,2017,550.30,0,0,0,0,0,0,0,0,0,0,0
CMP3,2017,160.95,0,0,0,0,0,0,0,0,0,0,0
CMP4,2016,3226.90,13141,13131.40,5108.60,4148,5529.60,1082.25,12945.85,5002.30,2239.80,4035.40,4454.35
CMP4,2017,13362.85,8671.35,10233,0,0,0,0,0,0,0,0,0
I have details of the company sales (row data) which is given to the crystal report. So In crystal report, I first group by data based on year and company. Total of each month is generated dynamic using crystal report sum field. Please help me on this.
This should be close to what you are looking for...
1) Make sure your data is grouped be year. (Which it sounds like you are)
2) Insert a SUM summary in the year group footer. (Also sounds good just make sure its in the group footer)
3) Use a formula like this...
Global CurrencyVar b := IF GroupNumber = 1 THEN Sum ({TableName.DollarAmount}, {TableName.Year}) ELSE b;
Global CurrencyVar e := Sum ({TableName.DollarAmount}, {TableName.Year});
Local NumberVar p := IF b = e OR b = 0 THEN 0 ELSE ((e - b) / b * 100); // or whatever calculation you are using...
b := Sum ({TableName.DollarAmount}, {TableName.Year});
p
4) Place the formula field in the group footer, next to the SUM from step #2.
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.
I want to print all the days of a given month in Crystal Report. This is what my Crystal Report looks like:
So on and so forth.
What I have done is, I created a table with dates, when the user pick a month through the date-timepicker my program will insert all the days of the picked month to the table.
Although it can be attempted at SQL level also (as suggested by #aMazing), if you want to do it at Crystal Report level only, you can adapt from the following basic idea to accomplish rows with dates having no records.
Create three formula fields in report design, namely First_Dates, Mid_Dates, Last_Dates and set their values in formula editor as under:
First_Dates
WhilePrintingRecords;
numberVar TotalDays := Day ({Sale_Date_Field}) - 1;
numberVar i;
stringVar DayList := "";
for i := 1 to TotalDays step 1 do
DayList := DayList & ToText(i, 0) & " 0.00 0.00" & Chr(13);
DayList;
Mid_Dates
WhilePrintingRecords;
numberVar FromDay := Day({Sale_Date_Field}) + 1;
numberVar To_Day := Day(Next({Sale_Date_Field})) - 1;
numberVar i;
stringVar DayList := "";
for i := FromDay to To_Day step 1 do
DayList := DayList & ToText(i, 0) & " 0.00 0.00" & Chr(13);
DayList;
Last_Dates
WhilePrintingRecords;
numberVar NextDay := Day ({Sale_Date_Field}) + 1;
numberVar i;
numberVar MonthDays := 30;
if (Month ({Sale_Date_Field}) in [1,3,5,7,8,10,12]) then
MonthDays := 31
else if (Month ({Sale_Date_Field}) in [4,6,9,11]) then
MonthDays := 30
else if (Month ({Sale_Date_Field}) = 2
and Remainder(Year({Sale_Date_Field}), 4) = 0) then
MonthDays := 29
else
MonthDays := 28;
stringVar DayList := "";
for i := NextDay to MonthDays step 1 do
DayList := DayList & ToText(i, 0) & " 0.00 0.00" & Chr(13);
DayList;
Now place these formula fields in your report as under:
First_Dates in Report Header Section
Mid_Dates in Details b Section
Last_Dates in Report Footer Section
Now enable Can Grow option for each of them in the Format Field on the Common tab.
Enable Suppress Blank Section option for Detail b Section in Section Expert.
Format the fields and DayList accordingly.
For multiple months the report can be grouped by Months and First_Dates, Last_Dates formulas can be placed in the Group Header and Footer respectively.
This solution will not work with Cross-Tab format.
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.