How to calculate gross margin Return on Investment in BEX
Hello Experts,
I need to create a Report where in I need to display Average last Valuated Stock of the Given month range in the selection screen
Example:
If I give the month selection range like 06.2006 to 08.2006
The Average should calculated like this
Gross Margin Return on Investment (GMROI)=
Closing Stock of 05.2005+closing Stock of 06.2006 + closing Stock of 07.2006+Closing Stock of 08.2006
Number of months i. e 4
But my problem is if I give the range like 06.2006 to 08.2006
Either this should take the previous months Closing Stock( I mean it should consider 05.2006 Closing Stock) or
Opening and Closing Stock of the 06.2006 closing stock of 07.2006 closing stock of 08.2006
But the number of months should be 4
How can I approach this scenario can any one give me the idea
Thanks and regards
DAB
Hi,
i think you can achieve this with two single Value variables.Because you would not able to define offset if use one variable to enter range.
1.Crate two single value,mandatory,ready for input variables on month lets assume ZMONTH1 and ZMONTH2 to enter from and To month values.assume ZMONTH1 for from value and ZMONTH2 is for To value.
2.in Query designer restrict month In free chars with thse two variables.but dont forget to select 'Value Range' instead of 'Single values' while restricting.You can swap the intervals if required by right clicking.
3.Now create 4 Restricted Keyfigures using offset on month.
in RKF1 ,Restrct month with ZMONTH1 and ofset value -1.
in RKF2 ,restrict month with ZMONTH1 and offset 0.
RKF3: ZMONTH2 and offset -1
RKF4: ZMONTH2 and ofset 0.
Just try it out and let me know whether it works or not.
Regards
Similar Messages
-
How to calculate First Date of Posting Period in BEx Query
Hi,
I have 2 reporting requirements as follows:
1) User will either enter a single posting period in a fiscal year or can enter a range of posting periods.
Based on user selection I need to display three key figures in a report.
Key figure 1 and Key Figure2 should be the summarized values for each posting period.
key Figure 3 should be the value on the first date of that particular posting period (in case user selects multiple posting periods i should derive the value of the first date of each posting period).
2) Also, in another report I need to display only top 8 values for one key figure in the report.
Please let me know the method or code required to get this Functionality.
Thanks in advance.First Report
1. Create Restricted KeyFigure 1 & 2 for the summarized values.
2. Create a Customer Exit Variable for getting the first date of the posting period, this should be of type Interval. Write code using FM FIRST_DAY_IN_PERIOD_GET to get. Read the selection variable to see the range of posting period and you have to insert that many first dates into this variable.
3. Create a new Restricted KeyFigure 3 and use the Customer Exit variable created in Step 2
Second Report
Use the Top N functionality of BEx and create a workbook. You can set the option Refresh query when the workbook is open so that the data is current when opened.
Hope this helps. -
How to calculate New customers and Returning customers in a Pivot Table?
Hi,
I have a Pivot table with columns as Order Date, Customer Name, Qty, Cost, Freight, Invoice, Adv Payment. I have only 30 customers and 11000 transactions for 4 years sales period.
How to calculate New customers and Returning customers in Pivot Table for any given Month or Quarter or Year. I am open to use helper column, formula or a calculated field etc
Thanks
ArjunHi Arjun,
I have received the file and read it, based on your further explain, I know your requested more clarity. In my view, the requested could be done via VBA code or Select function in other dataset, like Access/SQL. (Because before we count the new
customer and return customer, we might to filter them via rule, the formula need to assign the customer one by one. So, it's inefficient)
Thus, I recommend we try the above workaround: Use macro or Select function in Access. If you have further question about the coding, please post to the MSDN forum for Excel
http://social.msdn.microsoft.com/Forums/en-US/home?forum=exceldev&filter=alltypes&sort=lastpostdesc
The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.
George Zhao
TechNet Community Support
It's recommended to download and install
Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
programs. -
If I have a 10% Gross Margin formula can I change one task to calculate at 15%
I am working in MS Project 2010 Pro, I have set a column with a custom field to a 10% Gross Margin formula, is there a way I can change one task to a 15% Gross Margin formula?
I am also having a problem opening two project schedules at once, for some reason when I open the second schedule it's like I lose the schedule.
Thank you for all the help,
CeliaJohn,
I am trying the formula Rod suggested up in the thread:
[Cost]*(1+[Number1]).
Now to edit the margin for individual tasks you just edit Number1.
Thank you,
Celia -
Report for calculating gross margin
Hello Experts,
We need a report where we can find the gross margin .
We have wholesale and Retail where the items are set up in a way that the date goes to the same journal entry.How can we separate this and calculate the gross margin for different BP type .BP code for wholesale starts with "W" and for retail it starts "C".
Any help/suggestion is greatly appreciated.Hi,
Have you tried Sales Analysis report by customer? You can select different groups of customer by BP code.
Thanks,
Gordon -
How to calculate average value?
Hi all,
I'm using Lumira 1.15. I'm doing some practices with the sample dataset BestRunCorp... I want to calculate the average value of gross margin which is grouped by lines so that I can use a line chart to show the difference between the gross margin value and average value.
How can I achieve this ?
Best regards,
ShuangIt looks like it calculates the average based on the dimension
See below:
If you take the "Best run" Excel file, sort by country, calculate the average in Excel, it matches Lumira's 4,056 (for Argentina)
I am not sure I follow your divide by 12 logic? -
Hi,
How do we calculate the Product wise Gross Margin.
ThanksI believe you are talking about Item wise profit report. What exactly are you looking for in this report.
There are system reports that could help you with this.
Have you tried the Sales A/R > Sales Reports > Sales Analysis..run it from the Items tab -
How to calculate first date and end date of this year in Query
Hi Expert
I want to calculate following dates with inputted date in query.
I have no knowledge on ABAP and I just can create a query with simple logic.
Could you teach me how to calculate following date?
(If inputted date is April 12 2009)
- First date of this year (Ex January 1 2009)
- End date of this year (Ex December 31 2009)
- First date of last year (Ex January 1 2008)
- End date of last year (Ex December 31 2008)
- First date of this month (Ex April 1 2009)
Thank you!
TakeHR_JP_MONTH_BEGIN_END_DATE use this FM to get the begin and end date of the Date you are passing. eg when u give input as 04/12/2009, it will return
04/01/2009 as begin date
04/30/2009 as end date
pass the Year in this FM HR_E_GET_FISC_YEAR_DATES, you will get the Fiscal year Begin and End Dates
Abh -
BAPI_ACC_INVOICE_RECEIPT_POST how to calculate tax
Hallo folks,
i can't figuere out how to calculate the tax with the bapi BAPI_ACC_INVOICE_RECEIPT_POST. I already searched the Forums and google but no Solution helped me.
I don't really get it, which fields i have to fill. For example i do i have to fill the amt_base for every item or just for the tax structure?
ls_accgl-comp_code = ls_outtab-zzfaleiemp.
ls_accgl-tax_code = 'V3'.
ls_accgl-profit_ctr = ls_outtab-prctr.
ls_accgl-sales_ord = ls_outtab-kdauf.
ls_accgl-s_ord_item = ls_outtab-kdpos.
APPEND ls_accgl TO lt_accgl.
CLEAR ls_curamt.
ls_curamt-itemno_acc = l_itemno.
ls_curamt-currency_iso = 'EUR'.
ls_curamt-amt_doccur = ls_outtab-zzsum.
ls_acctax-itemno_acc = l_itemno.
ls_acctax-tax_rate = '19.000'.
ls_acctax-gl_account = ls_accgl-gl_account.
ls_acctax-tax_code = 'V3'.
ls_acctax-acct_key = 'VST'.
ls_acctax-cond_key = 'MWVS'.
APPEND ls_acctax TO lt_acctax.
CLEAR ls_curamt.
ls_curamt-itemno_acc = l_itemno.
ls_curamt-currency = 'EUR'.
* ls_curamt-amt_doccur = l_sum.
ls_curamt-amt_base = l_sum.
APPEND ls_curamt TO lt_curamt.
Because it doesn't matter what field i fill in TA FB03 there never come any taxes up.
has anybody some Ideas?
Best regards
MathiasHi,
check the below code
Read Invoice Work item data
CLEAR: lwa_inv_header.
SELECT SINGLE * INTO lwa_inv_header
FROM zbw_inv_header
WHERE zinv_id = i_documentheader-zinv_id.
IF sy-subrc = 0.
Get history line count
SELECT COUNT(*) INTO lv_hist_lineid
FROM zbw_wi_history
WHERE zinv_id = i_documentheader-zinv_id.
Get exception line count
SELECT COUNT(*) INTO lv_lineid
FROM zbw_wi_exception
WHERE zinv_id = i_documentheader-zinv_id.
Get document type
SELECT SINGLE zdoctype INTO lv_doc_type
FROM zbw_doc_types
WHERE zinvtype = i_documentheader-zinvoicetype AND
zinvind = i_documentheader-invoice_ind.
IF sy-subrc <> 0.
CLEAR t_return.
t_return-ztype = 'E'.
t_return-zmessage = 'Document type configuration is not done'.
APPEND t_return.
lv_lineid = lv_lineid + 1.
CLEAR lwa_exceptions.
lwa_exceptions-zinv_id = i_documentheader-zinv_id.
lwa_exceptions-zlineid = lv_lineid.
lwa_exceptions-zstep_id = i_stepid.
lwa_exceptions-zuser = sy-uname.
lwa_exceptions-zdate = sy-datum.
lwa_exceptions-ztime = sy-uzeit.
lwa_exceptions-zexception = t_return-zmessage.
MODIFY zbw_wi_exception FROM lwa_exceptions.
EXIT.
ENDIF.
Read posting date config
SELECT SINGLE * INTO lwa_posting
FROM zbw_posting_date
WHERE zarea = i_documentheader-zinvoicetype.
IF sy-subrc <> 0.
CLEAR t_return.
t_return-ztype = 'E'.
t_return-zmessage = 'Posting date configuration is not done'.
APPEND t_return.
lv_lineid = lv_lineid + 1.
CLEAR lwa_exceptions.
lwa_exceptions-zinv_id = i_documentheader-zinv_id.
lwa_exceptions-zlineid = lv_lineid.
lwa_exceptions-zstep_id = i_stepid.
lwa_exceptions-zuser = sy-uname.
lwa_exceptions-zdate = sy-datum.
lwa_exceptions-ztime = sy-uzeit.
lwa_exceptions-zexception = t_return-zmessage.
MODIFY zbw_wi_exception FROM lwa_exceptions.
EXIT.
ENDIF.
IF lwa_posting-zcurrentdate = 'X'.
Todays date as posting date
lwa_documentheader-pstng_date = sy-datum.
ELSE.
lv_today = sy-datum.
CLEAR: lv_days,
lv_months,
lv_years,
lv_calcdt.
Calculate last day of previous month as posting date
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
date = lv_today
days = lv_days
months = lv_months
signum = '-'
years = lv_years
IMPORTING
calc_date = lv_calcdt.
IF sy-subrc <> 0.
CLEAR t_return.
t_return-ztype = 'E'.
CONCATENATE 'Error while calculating the'
'Last day of previous month'
INTO t_return-zmessage SEPARATED BY space.
APPEND t_return.
lv_lineid = lv_lineid + 1.
CLEAR lwa_exceptions.
lwa_exceptions-zinv_id = i_documentheader-zinv_id.
lwa_exceptions-zlineid = lv_lineid.
lwa_exceptions-zstep_id = i_stepid.
lwa_exceptions-zuser = sy-uname.
lwa_exceptions-zdate = sy-datum.
lwa_exceptions-ztime = sy-uzeit.
lwa_exceptions-zexception = t_return-zmessage.
MODIFY zbw_wi_exception FROM lwa_exceptions.
EXIT.
ENDIF.
CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
EXPORTING
day_in = lv_calcdt
IMPORTING
last_day_of_month = lwa_documentheader-pstng_date
EXCEPTIONS
day_in_no_date = 1
OTHERS = 2.
ENDIF.
Populate the header data
lwa_documentheader-obj_type = 'IBKPF'.
CONCATENATE sy-datum sy-uzeit lwa_documentheader-comp_code
INTO lwa_documentheader-obj_key.
lwa_documentheader-obj_sys = sy-sysid.
lwa_documentheader-username = sy-uname.
lwa_documentheader-header_txt = 'HD BAPI Test'.
lwa_documentheader-comp_code = i_documentheader-comp_code.
lwa_documentheader-fisc_year = i_documentheader-zfisc_year.
lwa_documentheader-doc_date = i_documentheader-doc_date.
lwa_documentheader-trans_date = sy-datum.
lwa_documentheader-fis_period = i_documentheader-zfisc_period.
lwa_documentheader-doc_type = lv_doc_type.
ALL ITEM DATA *
Populate Account payble data
CLEAR lt_accountpayable.
lt_accountpayable-itemno_acc = 1.
lt_accountpayable-vendor_no = i_documentheader-zvendor.
lt_accountpayable-item_text = 'Webdesk invoice posting'.
APPEND lt_accountpayable.
clear lt_accountpayable.
Populate the currency for Account payble
CLEAR lt_currencyamount.
lt_currencyamount-itemno_acc = 1.
lt_currencyamount-currency = i_documentheader-currency.
lt_currencyamount-amt_doccur = i_documentheader-gross_amount * -1.
APPEND lt_currencyamount.
clear lt_currencyamount.
Loop the GL table
CLEAR lv_errfl.
LOOP AT t_glacc.
CONCATENATE i_documentheader-supcountry t_glacc-tax_code
INTO lv_vakey SEPARATED BY space.
SELECT knumh INTO lv_knumh
UP TO 1 ROWS
FROM konh
WHERE vakey = lv_vakey.
ENDSELECT.
IF sy-subrc = 0.
SELECT SINGLE kbetr INTO lv_kbetr
FROM konp
WHERE knumh = lv_knumh.
IF sy-subrc <> 0.
lv_errfl = 'X'.
ENDIF.
ELSE.
lv_errfl = 'X'.
ENDIF.
lv_kbetr = lv_kbetr / 10.
IF t_glacc-tax_base_amount IS INITIAL.
lv_taxamt = ( i_documentheader-gross_amount * lv_kbetr ) / 100.
ELSE.
lv_taxamt = ( t_glacc-tax_base_amount * lv_kbetr ) / 100.
ENDIF.
Populate the GL data
lt_accountgl-itemno_acc = 2.
lt_accountgl-gl_account = t_glacc-gl_account.
lt_accountgl-tax_code = t_glacc-tax_code.
lt_accountgl-acct_key = t_glacc-zacct_key.
lt_accountgl-item_text = 'Webdesk invoice posting'.
APPEND lt_accountgl.
clear lt_accountgl.
CLEAR lt_currencyamount.
lt_currencyamount-itemno_acc = 2.
lt_currencyamount-currency = i_documentheader-currency.
lt_currencyamount-amt_doccur = t_glacc-item_amount - lv_taxamt.
APPEND lt_currencyamount.
clear lt_currencyamount.
IF NOT t_glacc-tax_code IS INITIAL.
Populate the Tax data
lt_accounttax-itemno_acc = 3.
lt_accounttax-gl_account = t_glacc-ztaxgl_account.
lt_accounttax-tax_code = t_glacc-tax_code.
lt_accounttax-acct_key = t_glacc-zacct_key.
APPEND lt_accounttax.
clear lt_accounttax.
CLEAR lt_currencyamount.
lt_currencyamount-itemno_acc = 3.
lt_currencyamount-currency = i_documentheader-currency.
lt_currencyamount-amt_doccur = lv_taxamt.
IF t_glacc-tax_base_amount IS INITIAL.
lt_currencyamount-amt_base = i_documentheader-gross_amount.
ELSE.
lt_currencyamount-amt_base = t_glacc-tax_base_amount.
ENDIF.
APPEND lt_currencyamount.
clear lt_currencyamount.
ENDIF.
ENDLOOP.
IF lv_errfl = 'X'.
CLEAR t_return.
t_return-ztype = 'E'.
CONCATENATE 'Error while calculating the'
'Tax amount'
INTO t_return-zmessage SEPARATED BY space.
APPEND t_return.
lv_lineid = lv_lineid + 1.
CLEAR lwa_exceptions.
lwa_exceptions-zinv_id = i_documentheader-zinv_id.
lwa_exceptions-zlineid = lv_lineid.
lwa_exceptions-zstep_id = i_stepid.
lwa_exceptions-zuser = sy-uname.
lwa_exceptions-zdate = sy-datum.
lwa_exceptions-ztime = sy-uzeit.
lwa_exceptions-zexception = t_return-zmessage.
MODIFY zbw_wi_exception FROM lwa_exceptions.
EXIT.
ENDIF.
CALLING BAPI *
CLEAR lwa_wi_history.
lwa_wi_history-zinv_id = i_documentheader-zinv_id.
lwa_wi_history-zlineid = lv_hist_lineid.
lwa_wi_history-zstep_id = i_stepid.
lwa_wi_history-zuser = sy-uname.
lwa_wi_history-zdate = sy-datum.
lwa_wi_history-ztime = sy-uzeit.
CLEAR: lt_return[].
CALL FUNCTION 'BAPI_ACC_INVOICE_RECEIPT_POST'
EXPORTING
documentheader = lwa_documentheader
IMPORTING
obj_type = obj_type
obj_key = obj_key
obj_sys = obj_sys
TABLES
accountpayable = lt_accountpayable
accountgl = lt_accountgl
accounttax = lt_accounttax
currencyamount = lt_currencyamount
return = lt_return.
Thanks & Regards,
Sateesh. -
How to calculate acquisition value for specified day
Hi,
in my z program I have a problem how to calculate acquisition value for my asset for specified day.
Example:
I have asset created 8.7.2008 with TTYPE 104 (External asset acquisition) with value 5950.
30.11.2008 there is another TTYPE 272 (Retirement of current-yr acquis., w/o revenue) with value 950.
So BEFORE 30.11.2008 acquisition value is 5950. After is 5000. Is there any function module (or something else) in SAP system where I can send asset number and date a it return to me acquisition value for that day?
Many thanks for any answer!Hi,
your suggestion means that I have to compute acquisition value by myself (sum all TTYPE 1** - sum all TTYPE 2**). So SAP does't provide such functionality (LDB ADA have it, because it can compute acquisitiob value for specific day)?
Mant thanks for answer -
Hi,
Our Client handles no. of projects. How do we show Project wise Gross Margin either individually or by Group in SAP B1.Hi Suda,
I want only the gross margin(sales - direct cost) but not the net profit/loss. -
Ck11n:how to calculate the Quantity?
Dear all.
I use the tcode ck11n to create material cost estimate with quality structure.
And input the parameter like below:
Material = 600000-000000-0012
plant = 1000
Costing Variant = PPC1
Costing Lot Size = 1
After press return,the sap show the Itemization for material like below:
20.11.2008 Dynamic List Display 1
Itemization for material 600000-000000-0012 in plant 1000
Material 600000-000000-0012
Plant 1000
Costing Variant PPC1 Standard Cost Est. (Mat.)
Costing Version 1
Costing Date from-to 01.12.2008 - 31.12.9999
Lot Size 1 KARCarton
Cost Base 1 KARCarton
Cost of Goods Manufactured
ItmNo
ItemCat
Resource
Cost Eleme
Total
Fixed
Currncy
Quantity
Un
1
E
J0103033 WC1 A03
1001
14,400.00
7,200.00
CNY
3,600
CAR
2
E
J0103033 WC1 A01
1001
25,200.00
10,800.00
CNY
3,600
CAR
3
E
J0103033 WC1 A02
1001
14,400.00
7,200.00
CNY
3,600
CAR
4
E
J0103033 WC1 A04
1001
14,400.00
7,200.00
CNY
3,600
CAR
5
E
J0103033 WC1 A05
1001
14,400.00
7,200.00
CNY
3,600
CAR
6
M
1000 600000-000000-0013
40000002
9.00
0.00
CNY
3
CAR
7
G
CC_AT01 41000001
41000001
2.25
0.00
CNY
82,811.25
39,600.00
CNY
At the first line,the Resource was "J0103033 WC1 A03",and the Quantity was "3600".
I don't know why the Quantity was "3600" or where the Quantity come from?
So I need someone tell me how to calculate the Quantity?
Thank you so much.
Regards
YodaHi,
Pl note the Item Category, " M "- Material - The 3 quantity has been picked up from BOM correctly.
You are referring to Quantity 3600, which is against item category - E. Item category " E" means Internal activity allocation i.e the date flows through assignment to Routing. Check the Work center, Cost center & Activity types J0103033 WC1 A03 1001.
Now i think it is clear.
Cheers !
Siva
Cost of Goods Manufactured
ItmNo ItemCat Resource Cost Eleme Total Fixed Currncy Quantity Un
1 E J0103033 WC1 A03 1001 14,400.00 7,200.00 CNY 3,600 CAR
2 E J0103033 WC1 A01 1001 25,200.00 10,800.00 CNY 3,600 CAR
3 E J0103033 WC1 A02 1001 14,400.00 7,200.00 CNY 3,600 CAR
4 E J0103033 WC1 A04 1001 14,400.00 7,200.00 CNY 3,600 CAR
5 E J0103033 WC1 A05 1001 14,400.00 7,200.00 CNY 3,600 CAR
6 M 1000 600000-000000-0013 40000002 9.00 0.00 CNY 3 CAR
7 G CC_AT01 41000001 41000001 2.25 0.00 CNY -
Calculate gross profit, yearly sales,monthly sales,weekly sales?
hi all
i try to create procedures according to these conditions
What are my yearly sales?
What are my monthly sales?
What are my weekly sales?
What are my daily sales?
What is my Gross Profit?
What is my Gross Sales?
this is star schema
now how i calculate yearly sales, monthly sales, and also gross profit.
create procedure spgrossprofit
as
select as grossprofit from dimfact
now which aggregate function i use for calculate above conditions?
any help?Sorry(ETC) is a Spanish expression = the same for the next option
The correct query:
Year/Month
create procedure spyearlysales
as
select sum(totalsales),Year(Dimtime.date) from Dimtime
inner join Dimfact on Dimtime.Time_Key=dimfact.Time_Key
group by Year(Dimtime.date)create procedure spmonthsales
as
select sum(totalsales),year(Dimtime.date),Dimtime.Month from Dimtime
inner join Dimfact on Dimtime.Time_Key=dimfact.Time_Key
group by Year(Dimtime.date),Dimtime.Month
JM Claudio Dba/Consultor SQL/BI Pasiona - Spain -
How to calculate percentage and difference of two values in matrix report in ssrs 2008
Hi everyone,
DB--SQL server
SSRS-2008
I am creating matrix report with grouping on WEEK and Fiscalyearweek,
I need to calculate of difference between FY14W01,FY15W01 ande percentage of those..
how to calculate in ssrs level.
Thank You, Manasa.VHi veerapaneni,
According to your description, you want to calculated the increment percentage and difference between two fiscal year week within each week. Right?
In this scenario, since we need to do calculation based on values between dynamically generated cells, we can't simply use expression to achieve this goal. In this scenario, we need to use custom code to record the value for fiscal 14 and fiscal 15, then
we can calculate the difference and percentage within the column group. We have tested your case in our local environment, please refer to the steps and screenshots below:
1. Add the custom code below into the report (you may need to modify the data type based on your scenario:
Public Shared Value1 as Integer
Public Shared Value2 as Integer
Public Shared previous as string
Public Shared previousweek as string
Public Shared Function GetValue(Value as Integer,product as String,Week as String) as Integer
If product =previous and Week =previousweek Then
Value2=Value
Else
previous=product
previousweek=Week
Value1=Value
End If
return Value
End Function
Public Shared Function GetPct()
return (Value2-Value1)/Value1
End Function
Public Shared Function GetDiff()
return Value2-Value1
End Function
2. Design the matrix like below:
3. The result look like below:
If you have any question, please feel free to ask.
Best Regards,
Simon Hou -
How to calculate number of sundays and saturdays between two Dates
friends i want to calculate how many Sundays come in two Dates
i have tried following code which is hard coded i have to impliment method which can give me number of Sundays between two Dates
please help me
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar ;
import java.util.GregorianCalendar;
public class DateDiffCalculator {
private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MMM-dd");
public DateDiffCalculator() {
public static Date getDate (String date) throws Exception {
//log.debug(" "+date);
return SDF.parse(date);
public static Date getDate (Date date) throws Exception {
// log.debug("date is "+date);
return getDate(SDF.format(date));
public static long getDiffInDays(Date d1,Date d2) {
boolean isdiffGreaterThanYear=false;
long diffInMilliSeconds=d1.getTime()-d2.getTime();
return diffInMilliSeconds/(1000*60*60*24);
public static int getYear(String date) {
//String[] day= {Sun,Mon,Tue,Wed,Thu,Fri,Sat};
Integer year=new Integer(date.substring(0,4));
return year.intValue();
public static int getMonth(String date) {
//String date.substring(5,7);
System.out.println(" "+date.substring(5,8));
String m= date.substring(5,8);
int month=0;
if(m.equalsIgnoreCase("Jan")) {
month=1;
if(m.equalsIgnoreCase("Feb")) {
month=2;
if(m.equalsIgnoreCase("Mar")) {
month=3;
if(m.equalsIgnoreCase("Apr")) {
month=4;
if(m.equalsIgnoreCase("May")) {
month=5;
if(m.equalsIgnoreCase("Jun")) {
month=6;
if(m.equalsIgnoreCase("Jul")) {
month=7;
if(m.equalsIgnoreCase("Aug")) {
month=8;
if(m.equalsIgnoreCase("Sep")) {
month=9;
if(m.equalsIgnoreCase("Oct")) {
month=10;
if(m.equalsIgnoreCase("Nov")) {
month=11;
if(m.equalsIgnoreCase("Dec")) {
month=12;
return month;
public static int getDay(String date) {
Integer day=new Integer(date.substring(9,11));
return day.intValue();
public static int getNumberofSundays(String d1,String d2) throws Exception {
//d1 is leave start date d2 is leave end date
// get object in Date form
Date date1=getDate(d1);
Date date2=getDate(d2);
// now get calender objects from it
GregorianCalendar c1= new GregorianCalendar(getYear(d1),getMonth(d1),getDay(d1));
GregorianCalendar c2= new GregorianCalendar(getYear(d2),getMonth(d2),getDay(d2));
// get period
long leavePeriod = getDiffInDays(date1,date2);
return 12; // it should return number of sundays but we type 12 to perform compilation
public static void main(String[] arg)throws Exception {
System.out.println(" "+getNumberofSundays("2005-Oct-07","2006-Mar-01"));
}thanks now i have modified the get Month Code
as follows
public static int getMonth(String date) {
//String date.substring(5,7);
System.out.println(" "+date.substring(5,8));
String m= date.substring(5,8);
int month=0;
if(m.equalsIgnoreCase("Jan")) {
month=0;
if(m.equalsIgnoreCase("Feb")) {
month=1;
if(m.equalsIgnoreCase("Mar")) {
month=2;
if(m.equalsIgnoreCase("Apr")) {
month=3;
if(m.equalsIgnoreCase("May")) {
month=4;
if(m.equalsIgnoreCase("Jun")) {
month=5;
if(m.equalsIgnoreCase("Jul")) {
month=6;
if(m.equalsIgnoreCase("Aug")) {
month=7;
if(m.equalsIgnoreCase("Sep")) {
month=8;
if(m.equalsIgnoreCase("Oct")) {
month=9;
if(m.equalsIgnoreCase("Nov")) {
month=10;
if(m.equalsIgnoreCase("Dec")) {
month=11;
return month;
but question remains same how to calculate number of Sundays Between 2 Dates
Maybe you are looking for
-
Import FT Wizard - where's the imported site?
I downloaded the Import Front Page Site Wizard for Dreamweaver MX 2004 and then walked through the wizard to import my FP site. When I restart DW8, I get a message that the FP site has been added, but I don't see it anywhere. What gives?
-
Problem in import Outbound contact
Hello, I have a problem in import outbound contact. When I import a file of contact list, it works as I login agent in Finesse, it dial automatically. But when I import the same file again, it doesn't works. But after a period of time (30 mins) it wo
-
How To use window.print() into Button Attributes
hi, I want to print a report using an print button.so i am using window.print() function into Button Attributes .But Print pop up screen not pop up . How To use window.print() into Button Attributes . Thanks Manoj
-
Weblogic Server 9.2 Exception
Hi, Any body know about this Exception.We are getting in the production env.how to solve this problem. ####<Dec 8, 2009 12:57:26 AM PST> <Debug> <SecuritySSL> <corvus> <hpserver> <ExecuteThread: '13' for queue: 'weblogic.socket.M uxer'> <<WLS Kernel>
-
Hi. How can I get and set the scroll position of an table? VG