Using Date functions in DP macros
Hi all,
I am currently developing a macro in DP...and I need to do an action for the first period of a year.
I need to identify the first period for this purpose..I m using the date function Bucket_fiscal_period for this purpose but for soem reasons it is not giving a value of 01 for the first period.
The planning bucket has a weekly bucket pattern.
I tried to use the layoututvariable_set + layoutvariable and then bucket_fiscal_period to try and see if the values are getting set.But this seems not to be happening.
Can anybody tell me whats wrong here?
Thanks and Regards,
Anu
Hello,
If I am understanding your issue correctly you are trying to identify the weekly bucket in which the first day fo the year falls. To accomplish the same I guess the following should work:
OPTION 1:
IF
WEEK ( DATE ( BUCKET_BDATE ( X ) ) = 1
THEN
LAYOUTVARIABLE_SET ( 'FIRSTDAY' )
ENDIF
OPTION 2:
IF
YEAR_BDATE ( WEEK_BDATE () ) >= WEEK_BDATE ()
AND
YEAR_EDATE ( WEEK_BDATE () ) <= WEEK_BDATE ()
THEN
LAYOUTVARIABLE_SET ( 'FIRSTDAY' )
ENDIF
Hope this helps.
Regards,
Abhi
Similar Messages
-
How to use data function using characterstics variable for calculation on
how to use data function using characterstics variable for calculation on attribute as key figure
Hi Gayatri
Did you not see my answer for CASE because CASE does indeed offer the use of the BETWEEN clause, but DECODE does not. Let me give you a little synopsis of DECODE.
In its most simple form it takes 4 values and looks like this: DECODE(A, B, C, D)
This essentially means, IF A = B THEN C ELSE D
The trick to solving BETWEEN in a DECODE is to work out algoriths where A = B. Because we don't know how many values are between 00 and 99, although I could guess there were 100 we could of course have 100 parts in the DECODE but that would be awful. How about if we look at it another way and say this:
IF PART_NUMBER < 'SDK00' THEN pay_amount
ELSE IF PART_NUMBER > 'SDK99' THEN pay_AMOUNT
ELSE pay_amount + 100
This statement only had 2 hard coded values, but how to make DECODE work with less than? Easy, we use the LEAST function. The LEAST function takes 2 values and returns the one with the lowest value. So I use LEAST(PART_NUMBER, 'SDK00') then whenever the PART_NUMBER is lower than SDK00 it will be true. A similar situation exists for the opposite function GREATEST. Putting all of this together then, you can do this:
DECODE(PART_NUMBER, GREATEST(PART_NUMBER, 'SDK00'), DECODE(PART_NUMBER, LEAST(PART_NUMBER, 'SDK99'), PAY_AMOUNT * 100, PAY_AMOUNT), PAY_AMOUNT)
In English this can be read as follows:
IF the PART_NUMBER is greater than or equal to SDK00 and the PART_NUMBER is less than or equal to SDK99 THEN PAY_AMOUNT x 100 ELSE 0
Best wishes
Michael -
How to use date functions in BPEL
Hi All,
Is there any wayout for calculating no. of years with a given date and current date in BPEL.
I am developing a small application where I have to calculate the years of experience of the employees. I am given with the date of joining.I want to subtract the date of joining from the current date. Is there any way-out to calculate no. of years from the given date and current date in BPEL using date functions or something else.
Please suggest something..
Thanks in Advance
Roshni Shankaryou could use something like this in xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml"/>
<xsl:variable name="date1" select="xs:date('2001-01-01')"/>
<xsl:variable name="date2" select="xs:date('2010-01-10')"/>
<xsl:variable name="dif" select="$date2 - $date1"/>
<xsl:template match="/">
<all>
<date1>
<xsl:value-of select="$date1"/>
</date1>
<date2>
<xsl:value-of select="$date2"/>
</date2>
<dif-days><xsl:value-of select="fn:days-from-duration($dif)"/></dif-days>
<dif-years1><xsl:value-of select="fn:years-from-duration($dif)"/></dif-years1> <!-- gives 0 for me -->
<dif-years2><xsl:value-of select="fn:days-from-duration($dif) div 356"/></dif-years2>
</all>
</xsl:template>
</xsl:stylesheet> -
Print a DayName without using Date functions
Hi,
I have an assignment like without using any date functions i should print a calendar.
Below is the code without using any datefunctions like dateadd, datediff, datename a calendar has been generated for month and year entered. I want a week name for the dates like sunday ... monday etc.
I can take any date from calendar as reference and calculate based on that date.
ex: today is 2/20/2014 thursday . Next 7days again will be thursday, same way before 7days will be thursday.
I need to loop in below procedure and get weekname.
Plz help in the code,
I am using SQL server 2008
IF OBJECT_ID ('dbo.Calendar1') IS NOT NULL
DROP PROCEDURE dbo.Calendar1
GO
CREATE PROCEDURE [dbo].Calendar1 --4,1991
@month int,
@Year int
AS
BEGIN
declare
@startdateofMonthYear date,
@EnddateofMonthYear Date
Set @startdateofMonthYear=(Select cast(@Year as varchar(4)) +'-'+Right('00'+Cast(@month as varchar(2)),2) +'-'+'01')
Set @EnddateofMonthYear = (SELECT case when @month IN (1,3,5,7,8,10,12) then cast(@Year as varchar(4)) +'-'+Right('00'+Cast(@month as varchar(2)),2) +'-'+'31'
when @month IN(4,6,9,11) then cast(@Year as varchar(4)) +'-'+Right('00'+Cast(@month as varchar(2)),2) +'-'+'30'
else cast(@Year as varchar(4)) +'-'+Right('00'+Cast(@month as varchar(2)),2) +'-'+(CASE WHEN (@YEAR % 4 = 0 AND @YEAR % 100 <> 0) OR @YEAR % 400 = 0 THEN '29' else '28' End)
End)
;WITH CTE_DatesTable
AS
Select 1 daysint, Cast(SUBSTRING(cast(@startdateofMonthYear as varchar(20)),1,7) + '-'+CAST(1 as varchar(2)) as DATE) Calendardates
UNION ALL
SELECT daysint+1,Cast(SUBSTRING(cast(@startdateofMonthYear as varchar(20)),1,7) + '-'+CAST(daysint+1 as varchar(2)) as DATE) Calendardates
FROM CTE_DatesTable
WHERE daysint<=
(SELECT case when @month IN (1,3,5,7,8,10,12) then 31
when @month IN(4,6,9,11) then 30
else (CASE WHEN (@YEAR % 4 = 0 AND @YEAR % 100 <> 0) OR @YEAR % 400 = 0 THEN 29 else 28 End)
End)-1
Select
[DWDateKey]=Calendardates,
[DayDate]=daysint,
[MonthNumber]=@Month,
[MonthName]=Case when @month = 1 then 'January'
when @month = 2 then 'February'
when @month = 3 then 'March'
when @month = 4 then 'April'
when @month = 5 then 'May'
when @month = 6 then 'June'
when @month = 7 then 'July'
when @month = 8 then 'August'
when @month = 9 then 'September'
when @month = 10 then 'October'
when @month = 11 then 'November'
when @month = 12 then 'December'
End,
[Year]=@Year
From CTE_DatesTable
END
bhavanaIn the above code, where do i pass the year and month?
(Select 2000 YearID
Union All
Select YearID +1 From cte where YearID <2100
In above condition from 2000 year its displaying.
If i want in 90's year , Day name will not be correct.
Deepa -
How to use date function in my procedure
hi Gurus,
i have a requirement
where user passes the end_date parametre from front end which get convered to
End Date => 2012/05/31 00:00:00
now i based on this end date value i have to calculate the start date which is only month less than the end date, i know i can use add_months function for this requirement but
my problem is
l_start_date :=add_months(fnd_date.canonical_to_date(p_end_date),-1);
(OR)
l_start_date := add_months(to_date(end_date,'DD-MON-YYYY'),-1);
all these are returning date format as DD-MON-YYYY eg;
if user passes from front end 31-may-2012 , in the backend to my procedure it is passing as 2012/05/31 00:00:00
and my procedure calculating start date and returning as '01-MAY-12',
but my requiremnt is
it should return
Start Date => 2012/05/01 00:00:00
any pointers on this is highly appreciable,
thanks in advanceeHuaMin Chen wrote:
BluShadow wrote:
HuaMin Chen wrote:
Try
select trunc(to_date('22-AUG-03'), 'MONTH') from dual;?? That is so wrong.
Is that date 22nd August 2003? 22nd August 1903? 3rd August 2022? 3rd August 1922?
You have no date format specified in your to_date function.That is fine for 10g or above versions. Thank you.It way work, if you're lucky, but it depends on your sessions NLS settings...
SQL> select trunc(to_date('22-AUG-03'), 'MONTH') from dual;
TRUNC(TO_DATE('22-AU
01-AUG-0003 00:00:00
SQL> alter session set nls_date_format = 'YYYY-MM-DD';
Session altered.
SQL> select trunc(to_date('22-AUG-03'), 'MONTH') from dual;
TRUNC(TO_D
0022-08-01
SQL> alter session set nls_date_format = 'HH:MI:SS YYYY-MM-DD';
Session altered.
SQL> select trunc(to_date('22-AUG-03'), 'MONTH') from dual;
select trunc(to_date('22-AUG-03'), 'MONTH') from dual
ERROR at line 1:
ORA-01849: hour must be between 1 and 12
SQL>So it's certainly not "fine". It's bad practice.
This must be fine
select trunc(to_date('22-AUG-03','dd-MON-RR'), 'MONTH') from dual;That's better. -
Running Total (or) Moving Sum (or) Rollup using Date functions
I have to pass the Begin date and End date using prompt in my application (for daily basis for one month, monthly and yearly).
How can i use the date function for Rollup the days values(running total) for the below mentioned SQL
Table.Date field (@Prompt('Begin_Date','D',,mono,free) and @Prompt('End_Date','D',,mono,free)
@prompt automatically takes the begin date and end date.
I need the sql for rollup(running total) on daily basis for one month say jan 1 to jan 31.
Any idea?Check the Oracle on-line documentation on the ROLLUP option of the GROUP BY clause. It should be able to give you running totals.
-
Previous quarter from the current date using Date functions
hi all,
how can i get the value of the previous quarter and previous month using using NOW() function in the formula.
regards,
Rk
Edited by: Rk on Feb 13, 2009 9:28 AMHi Pk,
This "DSTR(DADD(NOW(),-1,'Q'),'YYYYQ')" will give you just an year 2008 (if you run this today).
But this "DSTR(DADD(NOW(),-1,'Q'),'YYYYMM)" will give you an year and month of prev quarter
200811(if you run this today)
Ola -
PL SQL using date functions to find partitions
I am trying to teach myself PL SQL and can use a bit of help. I am trying to automate the
dropping of paritions.
Can somebody provide me with an example of how to create some code that will return a liist
of partitions that are older than the N number of years (current year 1/1/2011), or N number of
months, weeks or days...
For example, today is 3/4/2011 How would I create code that will find me partitons that are
older than 2/1/2011 (current first of month -1 month, or ciurrent first of month -N months).
My partition names for all my tables are all in this formate P_YYYY_MM-DD
Please keep in mind this query can retrurn no rows, one row or several rows. If nothing is retrurned
I woiuld liike to print that out for each table.
Thanks in advance to all who answerThis would be a combination of sysdate and either add_months(date,number_of_months) or date-number_of_days, along with a conversion of the date to a pattern that matches your partition name format. Fortunately you've chosen a sensible format that sorts correctly.
So for finding the number of partitions older than so-many years:
select count(*)
from user_tab_partitions
where table_name = ... and
partition_name < to_char(add_months(sysdate,-12*5),'"P"_YYYY_MM-DD') Just be careful about whether you want partitions for which the oldest possible date is older than so-many years, or for which the newest possible date is older than so-many years.
Edit: Oh bear in mind that if you select only COUNT(*) then you'll always get a row back even if no matching partitions are found, and COUNT(*) will be 0. If you selected table_name and count(*) then you would get no rows back for tables that have no matching partitions. COUNT(*) never returns null.
Edited by: David_Aldridge on Mar 3, 2011 11:15 PM -
Get particular day by using date functions in bpel
Hi all,I want to get the 2nd day from every month of every year.Any body please suggest me how to write the xpath expression for this in bpel .Thq!
Edited by: 851924 on Dec 28, 2011 2:12 AMNot possible....you have to use java embedding.
-
Queries with date functions using PreparedStatement for multiple DB
I am developing application that uses DB independant queries. I am using preparedstatement to process the queries. I need to use date functions for query selection criteria.
for eg.
selecting the list of employees who had joined in the last 15 days
selecting list of employees who had joined between two dates etc.
where Date Joined field is a Timestamp value. To extract date no DB specific function can be used.
If I use setMonth, setYear etc.. to set params in the pstmt the query becomes complex in the above case. Can any one throw some light on how to do the above in preparedstatement or any other better alternative.
Tx a lotHi,
I did not mean that way. I presume that there is a timestamp value (may be a date too) column in the table. Then based upon your requirement (say before 15 days) pass the value as date (or time stamp) in the query as a parameter.
String qry = "select * from myTable where join_date <= ?";
stmt.setDate(1,myDate); // this is where you will have to manipulate the value to suit your DB timestamp or date value; you will have compatibility issues with util.Date and sql.Date so use Calendar class to satisfy.Feel free to mail me if you need further clarifications to [email protected]
Cheers,
Sekar -
I have recently written my first stored procedure.
Its rather a bunch of SQL statements.
I had to hard code lot of dates. most of them are first day of the current monthe or last day of current month etc.
I thot of parametrizing all the dates, but if a business person has to include all the parameters they could go wrong and get the wrong results.
Now, I want to use date functions to achieve these requirements:
Can any one please throw some insght into this:....
1) First day of current month,
2) last day of current month.
3) first day of previious month
4) last day of previous month
5) first day of a month that is 3 months from now.
6) last day of a month that is 3 months from now.
7).....
Can any one please throw some light on any one of this.. I can try to work from there onwards ....
Thanks a lot in advance,
AcHi there,
1) First day of current month
select trunc(sysdate, 'MM') from dual;
2) last day of current month.
select trunc(add_months(sysdate, 1), 'MM') - 1 from dual;
3) first day of previious month
select trunc(add_months(sysdate, -1), 'MM') from dual;
4) last day of previous month
select trunc(sysdate, 'MM') - 1 from dual;
5) first day of a month that is 3 months from now.
select trunc(add_months(sysdate, 3), 'MM') from dual;
6) last day of a month that is 3 months from now.
select trunc(add_months(sysdate, 4), 'MM') - 1 from dual;cheers,
Anthony -
Hi All,
I am trying to use date function in XSLT, I am using the below code, please correct me if i am wrong
<corecom:EffectiveDate>
<xsl:value-of select='xp20:format-dateTime(ns0:Segment-DTM/ns0:Element-373,"[YYYY][M01][D01]")'/>
</corecom:EffectiveDate>
Regards
FrancisHi Francis,
It doesn't seem to be anything wrong with the code itself, but what's the content of ns0:Segment-DTM/ns0:Element-373 ???
The xp20:format-dateTime function will work if the date on the first parameter is on ISO 8601 format...
http://www.w3.org/TR/NOTE-datetime
Examples
1994-11-05T08:15:30-05:00 corresponds to November 5, 1994, 8:15:30 am, US Eastern Standard Time.
1994-11-05T13:15:30Z corresponds to the same instant.
Cheers,
Vlad -
Hi
I have problem regarding date function in the following statment and unable to sort out the real cause as yet, i am not finding any materail for using date function in sql where clause any one can help me why is it.
Sector Table
Sect_Id Varchar2(2),
Sect_name Varchar2(100),
Wef Date
:Adate--->Forms Field ,Datatype --->Char(11)
Trigger Post-Query <Block Level>
BEGIN
SELECT SECT_NAME INTO :SECTORNAME FROM SECTOR
WHERE SECT_ID=:SECTOR
AND TO_DATE(WEF,'MON-YYYY')=TO_DATE(:ADATE,'MON-YYYY');
EXCEPTION WHEN NO_DATA_FOUND THEN
MESSAGE ('DEFINE SECTOR SETUP...');
MESSAGE ('DEFINE SECTOR SETUP...');
END;
FRM-40735: POST-QUERY trigger raised unhandled exception ORA-01843.
Any help in this regard.
Thanks in advanceTO_DATE converts from a character string such as '2004-11-24' into an Oracle DATE. If you pass it an Oracle DATE, it first converts it to a character string using the default date format, then converts that back into a date. This is not only inefficient but unsafe, since the default date format can change, breaking your code.
TO_CHAR converts from various datatypes into a VARCHAR2 string. When converting from an Oracle DATE, it can provide the output in a variety of formats.
It's worth bookmarking the Oracle Documentation Library:
10g: download-west.oracle.com/docs/cd/B14117_01/nav/portal_3.htm
9i: otn.oracle.com/pls/db92/db92.docindex
TO_DATE(WEF,'DD-MON-YYYY')=TO_DATE(:ADATE,'YYYY-MM-DD');WEF is already a date. If you want to remove any time portion, use TRUNC(wef). -
How to use Date data type ?
Hi @,
I have to use date type in my datatype but the format for the same is different and i dont know where to specify the same please help?
Also how to define datetime type with format yyyy-mm-dd.Thh:mm:ss ?
If there any place to specify the format ? I have defined it in pattern ?please correct
RegardsHi
I guess you can do it message mapping by defining source and destination date types, using date functions currentDate, DateTrans, DateBefore, DateAfter, CompareDates
By default, format of date is
xsd:date
Value is interpreted as date in format CCYY-MM-DD (according to the enhanced representation of ISO 8601).
The abbreviations mean the following:
CC: Century
YY: Year
MM: Month
DD: Day
Regards,
Sai -
Hello,
I am trying to calculate Goods movement date and used DATE Function "Between" to find out the dates between BUDAT and Current Date/System Date(used date function NOW().
between(BUDAT,AGEING_DATE)
Validate syntax doesn't show any error, however while activating view I am getting below error:
Message :
Internal deployment of object failed;Repository: Encountered an error in repository runtime extension;Internal Error:Deploy Analytic View (CV): nnAttribute 'aging_day' is missing in node finalAggregation(CalculationNode (finalAggregation) -> attributes -> calculatedAttribute (GOODS_MOVEMENT_DATE) -> expression)nnThe following errors occured: Inconsistent calculation model (34011)nDetails (Errors):n- CalculationNode (finalAggregation) -> attributes -> calculatedAttribute (GOODS_MOVEMENT_DATE) -> expression: Attribute 'aging_day' is missing in node finalAggregation.n- CalculationNode (finalAggregation) -> attributes -> calculatedAttribute (GOODS_MOVEMENT_DATE) -> expression: Attribute 'budat' is missing in node finalAggregation.nnDetails (Warnings):n- cubeSchema: Default language not set. Use 'en'.nnnn<?xml version="1.0" encoding="utf-8"?><cubeSchema version="3" operation="createCalculationScenario"><calculationScenario name="Inventory_Aging/AV_INVENTORY_AGING_PER_SITE" schema="_SYS_BIC"><dataSources><olapDataSource name="dataSource" schema="_SYS_BIC"
Any inputs are highly appreciable.
BR
VijayaHi @Vijaya Lakshmi,
Could you please check this part of the error message in detail:
Error:Deploy Analytic View (CV): nnAttribute 'aging_day' is missing in node finalAggregation(CalculationNode (finalAggregation
BR
Prabhith
Maybe you are looking for
-
In BW Reporting what can be done without transport
Hi Experts, In BW Reporting what can be done without transport. Suppose RRI, DIS to Nav changes Please Detail or any documentation. Thanks
-
Recovery Problem Qosmio X305-Q705
When ever i start recovery the screen jams untill i release the 0 button .... and .... It shows HDD Recovery Message but starts the windows ? Dosent go into the recovery wizard ! This problem came suddenly and i have done the recovery many times in t
-
I purchased an annual subscription to Adobe Acrobat pro but it doesn't operate on my Mac 10.5.8 operating system. Is there another Adobe product to which I should ask my subscription be switched so I can convert PDFs into Word and vice versa?
-
Hello Is it possible to remove the "" around every item when exporting to csv-format?
-
Computer asks if I want to allow the application ccpd to accept incoming network connections. Does anyone know what this is? This happens after a startup. I keep clicking deny, because I have no clue what this application could be. clicking the qu