Date Functions( first day of a month that is 3 months from now....)
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,
Ac
Hi 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
Similar Messages
-
Date for first day of current month
How can i get the date for first day of current month ?
select trunc(sysdate,'MM'),to_char(trunc(sysdate,'MM'),'DD'),to_char(trunc(sysdate,'MM'),'Day') from dual;
-
How to get the first day in the month from a domain date ?
Hi,
I like to know how to get the first day in the month from a domain date?
Thanks
StephenHi Gokul...
Instead of using the funtion module you can just write the 3 statements of code to get the first day of the week.
Its similar to the above one but instead of writing case statement you can achive the following.
data : w_res type i,
w_data type d,
w_res = w_date mod 7.
w_date = w_date - w_res.
write w_date.
This works.
Regards,
Siddarth -
How to - get first DAY of the month from the date ?
Hi
pls helphi,
data : DAYNR LIKE HRVSCHED-DAYNR,
DAYTXT LIKE HRVSCHED-DAYTXT.
data langu like sy-langu value 'EN'.
Parameters PDATE LIKE SY-DATUM.
PDATE+6(02) = '01'.
CALL FUNCTION 'RH_GET_DATE_DAYNAME'
EXPORTING
LANGU = LANGU
DATE = PDATE
CALID =
IMPORTING
DAYNR = DAYNR
DAYTXT = DAYTXT
DAYFREE =
EXCEPTIONS
NO_LANGU = 1
NO_DATE = 2
NO_DAYTXT_FOR_LANGU = 3
INVALID_DATE = 4
OTHERS = 5
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
WRITE :/ PDATE, DAYNR, DAYTXT.
(OR)
Try..
DATA:DAYNR LIKE HRVSCHED-DAYNR,
DAYTXT LIKE HRVSCHED-DAYTXT,
DAYFREE LIKE HRVSCHED-NODAY.
DATA:LANGU LIKE SY-LANGU ,
DATE LIKE SY-DATUM,
CALID LIKE P1027-CALID VALUE 'US'.
date = sy-datum.
date+6(2) = 01. "----->to get the first day .
*first day of the month
write:/ 'First date of the month', date.
*Day name
CALL FUNCTION 'RH_GET_DATE_DAYNAME'
EXPORTING
langu = SY-LANGU
date = DATE
CALID = CALID
IMPORTING
DAYNR = DAYNR
DAYTXT = DAYTXT
DAYFREE = DAYFREE
EXCEPTIONS
NO_LANGU = 1
NO_DATE = 2
NO_DAYTXT_FOR_LANGU = 3
INVALID_DATE = 4
OTHERS = 5
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
WRITE:/ DAYTXT.
Don't forget to reward if useful.... -
Date picker,first day/last day of month
Hi All
i have two items on my page
:p80_from_date
:p80_last_date
both of them are defined as date picker (dd/mm/yyyy)
i want that the form_date will contain allways the first day of the month the the user is picking
example suppose that the user picks in the :p80_from_date : '20/07/2009'
then the date suppose to be '01/07/2009'
if the user picking :p80_last_date '01/08/2009' the date suppose to be '31/08/2009' .
i've tried to do it with computation with no success.
i rather that after the user is picking the date he will see that the default is always the first date.
how shall i do it ?
thanks in advanced
NaamaHello Naama,
Now you are actually raising a new issue of date validation, which should pertains to every date field on your application.
>> the problem is that the function is not returning Boolean
It seems to me that you are mixing Computations and Validations. The first can set the value of an item; the second can raise an application error and include options of using a function that returns Boolean or an error text.
The problem in your specific case is that you need to validate the date prior to using it in your Computation, however the APEX engine fires Computations before Validations. The solution might be to use a PL/SQL process with a firing point of “On Submit – Before Computations and Validations”.
As I mentioned before, date validation should apply to all your application date items. Personally, I’m using a client side validation, fired by an onblur event, to give the user a “fair warning”. The following code matches your date format, and I’m using it in a Right-To-Left application (In the example it includes Hebrew error messages that can be changed to any text in any language you need). This function can deal with a fully formatted date string (e.g. 31/01/2010) or a string of numbers representing the date (e.g. 31012010).
function dateValidation(pThis){
var monthDays = [00,31,28,31,30,31,30,31,31,30,31,30,31];
var date_len = pThis.value.length;
if (date_len == 0){ // Date field is empty
return true; // or an error alert if date is mandatory
if (date_len == 10) {
pThis.value = pThis.value.substr(0,2)+pThis.value.substr(3,2)+pThis.value.substr(6,4);
else {
if (date_len != 8) {
alert('DD/MM/YYYY התאריך חייב לכלול 8 ספרות במבנה');
pThis.focus();
return false;
var DD = parseInt(trimLead0(pThis.value.substr(0,2)));
if (DD < 1) {
alert('מספר הימים אינו חוקי');
pThis.focus();
return false;
var YYYY = parseInt(pThis.value.substr(4,4));
if (YYYY < 1900 || YYYY > 2050){
alert('טווח השנים המוכר 1900-2050');
pThis.focus();
return false;
var MM = parseInt(trimLead0(pThis.value.substr(2,2)));
// Checking for leap year if MM=02
if (MM == 2) {
var leap = (((YYYY % 4 == 0) && ( (!(YYYY % 100 == 0)) || (YYYY % 400 == 0))) ?1:0);
if ((leap && DD > 29) || (!leap && DD > 28)) {
alert('מספר הימים בפברואר אינו חוקי');
pThis.focus();
return false;
else {
if (DD > monthDays[MM]) {
alert('מספר הימים בחודש זה אינו חוקי');
pThis.focus();
return false;
if (DD < 10) { DD = '0'+DD; }
if (MM < 10) { MM = '0'+MM; }
pThis.value = DD+'/'+MM+'/'+YYYY;
return true;
function trimLead0(str) {
return str.replace(/^0*/g,"");
}Best Practice stipulates that client side validation is not enough and you should use server side validations. In your specific case, if an end user tricked the client side validation he/she deserves to receive a system error message. Still, if you want to prevent it, you need to add some PL/SQL code that validates the input date before you use it in your Computation.
Regards,
Arie.
♦ Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.
♦ Author of Oracle Application Express 3.2 – The Essentials and More -
How to get first day of the month by the given date?
Now, is there function in CRM system that can get the first day of the month ?
for example:
input date is 2007/12/12, then return 2007/12/01 (the first day of month).
Thank you~Hi ping,
data: w_date type sy-datum ,
w_temp(2) type c.
w_date = '20071212'.
w_temp = w_date+6(2).
w_temp = w_temp - 1.
w_date = w_date - w_temp.
write / w_date.
Plz Reward if useful,
Mahi. -
Function module to get the 'first day of next month'
Hi
I have a selection screen with input fields
1. period (month eg: 07)
2.year(fiscal year eg: 2008 )
If user enters 07 as month and 2008 as year, then I have to display 08/01/2008(MM/DD/YYYY) as output.
Requirement is to calculate the 'first day of next month'
I have written code for this requirement.But I am asked to use function mdule.
Please help me in this regard.
Thanks&Regards
Rama.Mekalahi try this FM ...
HR_JP_MONTH_BEGIN_END_DATE
it gives the Begin Date and End date of the month
rewards points if found useful
regards,
Balaji -
Scheule a job that runs on first day of every month
Hi i want to schedul a job (run a procedure ) on first day of every month . I have done something lije this
declare
nextdate date;
begin
SELECT trunc(add_months(sysdate,1),'MM') into nextdate FROM DUAL ;
dbms_output.put_line(nextdate);
dbms_job.submit(
what=>'someprocedure',
next_date=>nextdate,
interval=>'30');
end;
is interval mandatory ? how can i define that interval ??Hi,
You can define an interval as follows:
SQL> alter session set nls_date_format='dd-mm-yyyy hh24:mi:ss';
Session altered.
SQL> select add_months(trunc(sysdate, 'mm'), 1) from dual;
ADD_MONTHS(TRUNC(SY
01-09-2009 00:00:00
1 row selected.
SQL> select add_months(trunc(sysdate, 'mm'), 1) + 7/24 from dual;
ADD_MONTHS(TRUNC(SY
01-09-2009 07:00:00So, if you want your job to start at 07.00 every month you submit:
declare
nextdate date;
begin
SELECT trunc(add_months(sysdate,1),'MM') into nextdate FROM DUAL ;
dbms_output.put_line(nextdate);
dbms_job.submit(
what=>'begin someprocedure; end;',
next_date=>sysdate,
interval=>'add_months(trunc(sysdate, ''mm''), 1) + 7/24');
end; untested
Check the docs: http://tahiti.oracle.com
and/or http://asktom.oracle.com
and/or this forum as well.
Do some searches and you'll find lots of examples. -
Function for finding first day of the month !!
Hi,
I know we have function to find the last day(DD) of the month. Do we have any functions for finding the first day of the month ??? if not is there any way i can find the first date(DD) of the month .
Bcoz i m trying to incorporate the logic for finding the first day of the month partition.
Thank you!!!Shahid Ali Tcs wrote:
There are many solution given by member in relation with your question, and all are correct .
I want to make u know something else.
Have you ever think why oracle has given function for last_day but no function for first.....
I u think this question u will get the answer of your "first day finding " question.
Because first day is alwasy 01 of every, while last day can be 30,31,29,28.....
Got my words ........
One more solution from my side,,,,
SQL> select '01' || to_char(sysdate,'-MON-YY') from dual;
'01'||TO_
01-SEP-09Which is a completely poor way of doing it.
Using TRUNC or LAST_DAY(..) + 1 will return a DATE datatype result.
Your method is converting the DATE into a VARCHAR2, which then prevents further processing/date based calculations unless it is explicitly converted back to a DATE again.
The reason Oracle hasn't provided a FIRST_DAY is because the TRUNC function already caters for it as this works with DATE's as well as NUMBER's, not because the first day is always 1. -
Function Modules to get First day of week, month, Year
Can anyone name the Function Modules for getting First day of week, month ,year.
to get first day of week use this function; WEEK_GET_FIRST_DAY
CALL FUNCTION 'WEEK_GET_FIRST_DAY'
EXPORTING
WEEK = '201107'
IMPORTING
DATE = l_date
EXCEPTIONS
WEEK_INVALID = 1
OTHERS = 2.
with DATE_COMPUTE_DAY function you can get date number in week.
CALL FUNCTION 'DATE_COMPUTE_DAY'
EXPORTING
DATE = workdate
IMPORTING
DAY = day_of_week_num
EXCEPTIONS
OTHERS = 8.
CASE day_of_week_num.
WHEN 1.
hold_day_of_week = 'Monday'.
WHEN 2.
hold_day_of_week = 'Tuesday'.
WHEN 3.
hold_day_of_week = 'Wednesday'.
WHEN 4.
hold_day_of_week = 'Thursday'.
WHEN 5.
hold_day_of_week = 'Friday'.
WHEN 6.
hold_day_of_week = 'Saturday'.
WHEN 7.
hold_day_of_week = 'Sunday'.
WHEN OTHERS.
hold_day_of_week = 'invalid'.
ENDCASE. -
ABAP for the first day of the month
Hello BW users,
I have a scenario which uses an ODS with cumulative key figures with Addition update type. An infocube gets data from ODS by start routine in cube's update rule. I update this ODS first then infocube. All the loads are Full and are loaded daily. This is a snapshot scenario and I load the ods on itself then load from another infocube let's say Cube1. After successful load, I update infocube on itself again then update from the same infocube, Cube1, as in ODS. Infocube load sequence is same as ODS. In the scenario ODS and infocube are wanted to be updated daily. Therefore, I have to delete the ODS's (since it is addition update type) and infocube's overlapping data in the process chain that automates the load. At this point I need two things:
1- ABAP program that is going to give me the first day of each month.
2- ABAP program that is going to delete the overlapping data in ODS when I load it daily. Since I can do that for infocube in process chain with standard process type of Delete overlapping requests from infocube I need it only for ODS. Because there is no standard process type to delete overlapping requests in ODS (since its update type is Addition).
I appreciate your help. Thank you in advance.
Sincerely,1- ABAP program that is going to give me the first day of each month.
if sy-datun+6(2) = 01.
SY-FDAYW should give you the day
endif.
2- ABAP program that is going to delete the overlapping data in ODS
REPORT <PGM NAME>.
TABLES: RSODSACTREQ , rsseldone.
Parameters : odsname type RSINFOCUBE default '<>ODS NAME'.
DATA: temp_REQUEST LIKE RSODSACTREQ-REQUEST,
temp_REQUEST1 LIKE RSODSACTREQ-REQUEST,
temp_RNR LIKE rsseldone-RNR.
DATA: BEGIN OF itab OCCURS 0,
REQUEST LIKE RSODSACTREQ-REQUEST,
TIMESTAMP LIKE RSODSACTREQ-TIMESTAMP,
END OF itab.
DATA: BEGIN OF itab1 OCCURS 0,
RNR LIKE rsseldone-RNR,
seldate LIKE rsseldone-seldate,
seltime LIKE rsseldone-seltime,
END OF itab1.
SELECT REQUEST TIMESTAMP FROM RSODSACTREQ INTO TABLE itab
WHERE ODSOBJECT = '<ODS NAME>'.
SORT itab DESCENDING BY TIMESTAMP .
READ TABLE itab INDEX 1.
temp_REQUEST = itab-REQUEST.
SELECT RNR seldate seltime FROM rsseldone INTO TABLE itab1
WHERE source = '<Info Source Name for the ODS>'.
SORT itab1 DESCENDING BY seldate seltime .
READ TABLE itab1 INDEX 1.
temp_RNR = itab1-RNR.
*If temp_REQUEST = temp_RNR .
CALL FUNCTION 'RSSM_PROCESS_REQUDEL_ODSO'
EXPORTING
I_ODS = odsname
I_REQUEST = temp_REQUEST
I_JOBNAME = 'i_jobname'
I_VARIANT =
I_INSTANCE =
IMPORTING
E_ERROR =
E_T_MSG = itab1
E_T_RNRLIST = ITAB1.
*else.
*raise exception.
*endif.
clear itab.
refresh itab.
SELECT REQUEST TIMESTAMP FROM RSODSACTREQ INTO TABLE itab
WHERE ODSOBJECT = '<ODS NAME>'.
SORT itab DESCENDING BY TIMESTAMP.
READ TABLE itab INDEX 1.
temp_REQUEST1 = itab-REQUEST.
if temp_REQUEST = temp_REQUEST1.
raise exception .
endif. -
How to get the date of first day of a week for a given date
Hi gurus
can any one say me how to get the date of first day(date of Sunday) of a week for a given date in a BW transformations. For example for 02/23/2012 in source i need to get 02/19/2012(Sunday`s date) date in the result. I can get that start date of a week using BWSO_DATE_GET_FIRST_WEEKDAY function module. But this function module retrieves me the start date as weeks monday(02/20/2012) date. But i need sundays(02/19/2012) date as the start date. So it would be really great if anyone sends me the solution.
Thanks
RavHi,
The simplest way would be to subtract 1 from the date date which you are already getting in transformation routine, but instead of doing that subtraction manually which might need bit of errort, you can simply use another FM to subtract 1 from given date.
RP_CALC_DATE_IN_INTERVAL
Regards,
Durgesh. -
Hi,
I created a data parameter and I want my date parameter default value to be the first day of previous month, the expression {$FIRST_DAY_OF_MONTH()$} is pointing to the fitst day of current month and when I tried {$FIRST_DAY_OF_MONTH()-1$} it is just subtracting a day(thought to go back one month)...Is there way I can point my default value to first day of previous month.?
Regardshmm is BI Publisher in Beta? Are there any workarounds you can suggest me to achieve this?
I see the user stated that a workaround is possible at RTF template level? How can we achieve this?
Re: Default date as first of month
Edited by: user8937215 on Aug 10, 2010 7:30 AM -
I want the minimum of the horizontal axis to be the first day of the month.
I have a situation where I want the minimum of the horizontal
axis(with date time axis) to be the first day of the month. I
attempt it like so:
var max:Date = new Date();//current date is our max from
which we will calculate the min
var min:Date = new Date(max.fullYear,max.month,1);
dateTimeAxis.minimum = min;
However this first date on this axis is the last day of the
previous month for example 31 August instead of 1 September. Any
ideas how to fix?Nikos, the only thing I can think of (off hand) is that it's
defaulting to "zero" hour on that date, if you tried:
var min:Date = new Date(max.fullYear,max.month,1,13);
Would that make it work? That would set the date to 1pm.
Have you considered defining the axis with the data you are
binding to?
Cheers,
David -
How to get the first day of current month
hi guys,
i am trying to get the first day of current month which get from the date i input at the selection screen. my method is not so good, so i was wondering if there is better way to get the this,
thanks.Try this .
data : DAYNR LIKE HRVSCHED-DAYNR,
DAYTXT LIKE HRVSCHED-DAYTXT.
data langu like sy-langu value 'EN'.
Parameters PDATE LIKE SY-DATUM.
PDATE+6(02) = '01'.
CALL FUNCTION 'RH_GET_DATE_DAYNAME'
EXPORTING
LANGU = LANGU
DATE = PDATE
CALID =
IMPORTING
DAYNR = DAYNR
DAYTXT = DAYTXT
DAYFREE =
EXCEPTIONS
NO_LANGU = 1
NO_DATE = 2
NO_DAYTXT_FOR_LANGU = 3
INVALID_DATE = 4
OTHERS = 5
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
WRITE :/ PDATE, DAYNR, DAYTXT.
Cheers
Maybe you are looking for
-
Change the play order of songs?
how do i change the play order of songs on my iphone? when i upgrade my iphone on itunes , that puts the last purchase to last on the list and i would listen first. the playlist in inverted. why?
-
Target file name using Dynamic Configuration
Hi, Currently we have requirement Idoc to File interface.In this scenario if one field exists infile then we have to check and we need to create update directory and if it is not exist then we should create one more directory and upload files over
-
Users unable to create tiered dashboards
I'm havng trouble with access rights on dashboard builder that I hope someone can help me with. Users are able to get to dashboard builder, and can even click on the Add button to add a new dashboard, but the Name field and Remove buttons are grayed
-
Ive created a bean and put it into a JAR package, all looks OK but there must be something wrong somewhere as I get the error message ... java.lang.LinkageError: duplicate class definition when I try to load it into beanbox. my JAR looks OK and conta
-
ASR(Auto Service Request) in Ops Center 11g?
Published document mentions it supports automatic service request generation, however no technical document describes how to implement. Any clue? Thanks in advance, Vince