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.
Similar Messages
-
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. -
Find 3rd friday of the month for a given date
how to find out 3rd friday of the month for a given date? I can always pass the first day of the month as input
eg, input date is 01-JAN-09. need to get the 3rd friday 16-JAN-09 (Jan has 5 fridays 02, 09, 16,23,30)
input date : 01-feb-09, need to get 20-feb-09
Edited by: user520824 on Apr 1, 2009 12:30 PMNLS independent solution:
SELECT DT,
TO_CHAR(DT,'FMDay') day,
CASE
WHEN TRUNC(TRUNC(DT,'MM') + 7,'IW') - 3 < TRUNC(DT,'MM') THEN TRUNC(TRUNC(DT,'MM') + 7,'IW') + 18
ELSE TRUNC(TRUNC(DT,'MM') + 7,'IW') + 11
END THIRD_FRIDAY_OF_THE_MONTH
FROM (
SELECT TO_DATE(LEVEL || '/2009','MM/YYYY') DT
FROM DUAL
CONNECT BY LEVEL < 13
DT DAY THIRD_FRI
01-JAN-09 Thursday 16-JAN-09
01-FEB-09 Sunday 20-FEB-09
01-MAR-09 Sunday 20-MAR-09
01-APR-09 Wednesday 17-APR-09
01-MAY-09 Friday 15-MAY-09
01-JUN-09 Monday 19-JUN-09
01-JUL-09 Wednesday 17-JUL-09
01-AUG-09 Saturday 21-AUG-09
01-SEP-09 Tuesday 18-SEP-09
01-OCT-09 Thursday 16-OCT-09
01-NOV-09 Sunday 20-NOV-09
DT DAY THIRD_FRI
01-DEC-09 Tuesday 18-DEC-09
12 rows selected.
SQL> SY. -
How to get last day of a month
using pl/sql
What i need is that all members whose birthdate is in the curren month will be included as having had their birthdate regardless of the date of the month. The code i have is:
Select me607.subscriber_id
me607.mbr_dob,
** trunc(months_between (*end of current month*,me607.mbr_dob) / 12) as age
from odw.mbr607_member_expanded me607
The asterixed line is what I need to change. If I put the end of the current month (where I put 'end of current month') then all those whose birthday month is in Feb will show as having had their birthdate. So if run today, folks whose birthdate is 26-feb-2005 will show an age of 5.
When grabbing the last day of the month using visual basic I just use the first day of the subsequent month minus 1. Any assistance is appreciated..Hi,
This does what you requested:
Select me607.subscriber_id, -- Don't you need a comma here?
me607.mbr_dob,
ROUND ( MONTHS_BETWEEN ( SYSDATE
, me607.mbr_dob
/ 12
from odw.mbr607_member_expanded me607
WHERE TO_CHAR (me607.mbr_dob, 'MONTH') =
TO_CHAR (SYSDATE, 'MONTH')
;If this is run sometime in February, 2010, and mbr_dob is sometime in Febrary, 2005, then the result of MONTHS_BETWEEN will be between 59 and 61. When we divide by 12 convert that to years, that difference of up to one month becomes so small that it will be lost in the rounding.
If this isn't exactly what you need, tthen post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
Edited by: Frank Kulash on Feb 17, 2010 1:32 PM
Added explanation. -
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.... -
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. -
How to get same day of a month in every year in the DB ( To update a flag )
Hi,
I am trying to formulate an update query for a flag table in our database which contains dates, and flag columns. Currently the system have dates for the next ten years. The flags are updated with values 0 or 1 if a particular date falls under the required criteria.
I need to update flag column for the same day of the month in every year. e.g. 2nd Sunday of October. The value should be updated to all years in the table. Currently I am using the following query to update the current year.
UPDATE FILTERCALENDAR SET YEAR_WINDOW=1 WHERE c_date = NEXT_DAY( TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1)*7;
and for next year Like
UPDATE FILTERCALENDAR SET YEAR_WINDOW=1 WHERE c_date = add_months(NEXT_DAY( TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1)*7,+12)-1;
This is not an excellent way to do it as it does not take care of leap years and it does not scan and update values in the whole table for all years correctly.
Can any one help me to resolve this please.Hi,
user10903866 wrote:
Hi,
I am trying to formulate an update query for a flag table in our database which contains dates, and flag columns. Currently the system have dates for the next ten years. The flags are updated with values 0 or 1 if a particular date falls under the required criteria.
I need to update flag column for the same day of the month in every year. e.g. 2nd Sunday of October. The value should be updated to all years in the table. Currently I am using the following query to update the current year.
UPDATE FILTERCALENDAR SET YEAR_WINDOW=1 WHERE c_date = NEXT_DAY( TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1)*7;That's the 2nd Sunday after October 1; the 2nd Sunday of October is the 2nd Sunday after September 30, so you need to subtract 1 more day before calling NEXT_DAY.
I'd do it this way:
WHERE c_date = NEXT_DAY ( TO_DATE ( '01-OCT-2013', 'DD-MON-YYYY') - 8
, 'SUNDAY'
) + (7 * 2) -- Last number is week numberRemember, calling NEXT_DAY like this depends on your NLS_DATE_LANGUAGE.
and for next year Like
UPDATE FILTERCALENDAR SET YEAR_WINDOW=1 WHERE c_date = add_months(NEXT_DAY( TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1)*7,+12)-1;If you want the 2nd Sunday in October, 2014, then take the previous expression, and just change 2013 to 2014:
WHERE c_date = NEXT_DAY ( TO_DATE ( '01-OCT-2014' -- or any month and year you want
, 'DD-MON-YYYY'
) - 8
, 'SUNDAY'
) + (7 * 2) -- Last number is week number
This is not an excellent way to do it as it does not take care of leap years and it does not scan and update values in the whole table for all years correctly.
Can any one help me to resolve this please.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
Explain, using specific examples, how you get those results from that data.
See the forum FAQ {message:id=9360002} -
How to get first day of calendar week ?
hi,
i'm storing some calendar weeks in my database. for example 30/2013.
How can i get the first day of this week (monday)? in this case it is 22.07.2013
thx
AnjaAs far as I know we don't have a function that converts week of a year into date. So you can try something like this.
SQL> with t
2 as
3 (
4 select '30/2013' week_year
5 from dual
6 )
7 select min(dt) week_start_day
8 from (
9 select (level - 1) + to_date('01-01-' || substr(week_year, -4), 'dd-mm-yyyy') dt
10 , week_year
11 from t
12 connect
13 by level <= to_date('31-12-' || substr(week_year, -4), 'dd-mm-yyyy') -
14 to_date('01-01-' || substr(week_year, -4), 'dd-mm-yyyy') +1
15 )
16 where to_number(to_char(dt, 'iw')) = to_number(substr(week_year, 1, instr(week_year, '/')-1));
WEEK_STAR
22-JUL-13 -
How to get last day of prev month?
SELECT to_char(SYSDATE, 'MM') -1, last_day(sysdate)
FROM DUAL;
If current month is April, How to get the last day of March? Thanks.SQL> select sysdate, trunc(sysdate, 'mm') - 1 from dual ;
SYSDATE TRUNC(SYSDA
06-APR-2004 31-MAR-2004
1 row selected.
SQL> -
How to get 10th day of every month?
Hi All,
please find the below requirement , how to achive this?
" Show the Actual as a bar on a monthly frequency, with Actual costs shown as they existed on the 10th business day of each month, going back six months – the Target can be shown as a line"
Please help me out
thanks
SwapnaHI ,
implement this function in ur colum edit
EVALUATE('TRUNC(%1,''MONTH'')+09',colmn_name)
u wil get answer for this requirement
regards
srinivas -
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 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 -
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 -
To get first day and last day of month.
Please help, I need a sql function that will return the first day of a month when I enter a date that is on or before the 15th and then returns the last day of the month when I enter a date of the 16th or later.
This is my query but I get ORA-00932: inconsistent datatypes: expected DATE got CHAR error.
select CASE
WHEN to_char(:p_date, 'DD') < 15 THEN
add_months((LAST_DAY(:p_date)+1), -1)
WHEN to_char(:p_date, 'DD') > 15 THEN
TO_CHAR(LAST_DAY(:p_date))
end
from dual;
ThanksHi,
please use the good habit to mark your questions as answered when you are satisfied with the answers.
Additionally when you put some code or output please enclose it between two lines starting with {noformat}{noformat}
i.e.:
{noformat}{noformat}
SELECT ...
{noformat}{noformat}
Regards.
Al -
How to get last day of the year
Hi All ,
Thanks in advance ...
How will I get the last day of the year as I am passing date at run time .
I can manage to get first day of year by
SELECT TRUNC(SYSDATE,'YEAR') AS FDAY_YEAR
from dual
Thanks in advance
Regards
Sachin1* select ADD_MONTHS(trunc(sysdate,'yyyy'),12)-1 dd from dual
SQL> /
DD
31-DEC-2010
Maybe you are looking for
-
Integrate BI queries in WD ABAP
Hi Experts Can somebody guide me as in how can we integrate BI queries in WD ABAP. Will we be using BI application frame UI or is there any other approach? Thanks Puneet
-
How do I fix my screen display? It scrolls vertically and horizontally
The screen on my 21.5 inch imac scrolls up and down and side to side instead of a static resolution. The display resolution is set to 1920 X 1080 on my imac. This glitch is really annoying but I don't know what to do. Help!
-
What does this error message mean: "Please acquire a new SIM (H5006)"
I tried accessing my cellular data and got this screen: "The SIM is currently active and not available for activation on this device" "Please acquire a new SIM (H5006)" Any ideas why this would happen? Thanks, Ron
-
never mind I got it thanks though
-
Repeating frame position problem!
HI! This is bothering me two days and i can't figure it out. I have 4 repeaitng frame hierarchly: R_frame_1 R_frame_2 R_frame_3 R_frame_4 4 th repeating frame is a problem because on the first page is everything ok data1 data2 data3 data4 but on seco