Function to retrieve first day of the month.
Select (sysdate, 'IW') from dual
I know this takes the date to Monday. Is there a function like above which takes the date back to first Monday of the month ??
Thanks in advance.
Hi,
NEXT_DAY is very handy, but it's dependent on NLS_DATE_LANGUAGE, and you can't pass an argument to override that.
TRUNC (dt, 'IW') does not depend on any NLS settings, so you might prefer this:
TRUNC ( 6 + TRUNC (SYSDATE, 'MONTH')
, 'IW'
) AS first_mondayThe 1st Monday of the month is the Monday on or before the 7th of the month.
Similar Messages
-
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 to retrieve all days of the previous month.
Hi,
Yes, it's a monthly report i've been given the task to achieve.
So, all I need is all days of previous month (even if there is no data for this day)
I've been instructed to use the following code, but it does not return any value:
DECLARE
CURSOR CUR_LAST_DAY IS
SELECT TO_CHAR (LAST_DAY (ADD_MONTHS (SYSDATE, -1) ), 'DD')
FROM DUAL;
VVA_LAST_DAY VARCHAR2 (2);
VNU_JOUR NUMBER := 0;
BEGIN
OPEN CUR_LAST_DAY;
FETCH CUR_LAST_DAY
INTO VVA_LAST_DAY;
CLOSE CUR_LAST_DAY;
WHILE VNU_JOUR <= TO_NUMBER (VVA_LAST_DAY) - 1
LOOP
VNU_JOUR := VNU_JOUR + 1;
END LOOP;
END;
--CLOSE CUR_LAST_DAY
--DEALLOCATE CUR_LAST_DAY-----
On the other end, i've developped this code:
SELECT TO_CHAR(SYSDATE,'dd')
FROM DUAL
WHERE TO_CHAR(SYSDATE,'dd') >= to_char(to_date(to_char(ADD_MONTHS(SYSDATE, -1),'yyyy-mm')||'-01'),'yyyy-mm-dd')
AND TO_CHAR(SYSDATE,'dd') < to_char(LAST_DAY(to_date(to_date(to_char(ADD_MONTHS(SYSDATE, -1),'yyyy-mm')||'-01'),'yyyy-mm-dd')));Which is returning a null value. :(
RegardsHello,
You want to retrieve complete days of last month from one query...so here it is..
SELECT
TO_DATE(LEVEL||'-'||TO_CHAR(ADD_MONTHS(SYSDATE,-1),'MON-YY'),'DD-MON-YY') COMP_DATE,
TO_CHAR(TO_DATE(LEVEL||'-'||TO_CHAR(ADD_MONTHS(SYSDATE,-1),'MON-YY'),'DD-MON-YY'),'DD') ONLY_DD,
TO_CHAR(TO_DATE(LEVEL||'-'||TO_CHAR(ADD_MONTHS(SYSDATE,-1),'MON-YY'),'DD-MON-YY'),'MM') ONLY_MM,
TO_CHAR(TO_DATE(LEVEL||'-'||TO_CHAR(ADD_MONTHS(SYSDATE,-1),'MON-YY'),'DD-MON-YY'),'YY') ONLY_YY
FROM DUAL
CONNECT BY LEVEL <= TO_NUMBER(TO_CHAR(LAST_DAY(ADD_MONTHS(SYSDATE,-1)),'DD'))I am not at database machine so therefore not tested.
But one thing keep in mind that this forum only for reports there is separate forum for sql and pl/sql.
Function to retrieve all days of the previous month.
-Ammad
Edited by: Ammad Ahmed on Apr 22, 2010 10:53 PM
Spelling Mistake -
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. -
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.... -
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 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 -
Is there any funcions available to pick up first day of the month?
I want to show the first month of the year given any date time stamp as input..
eg:
select sysdate from dual
assume sysdate is 10 Mar 2005
the output should be 10 Jan 2005.
We can take the last day of the month by using last_day
how to take the first day of the month given a input datetime?I want to show the first month of the year given any date time stamp as input..There is a little confusion with the thread's title.
We all answered you about your title question : how to obtain the first day of month, not the first month of year. For which you can test something like this :
SQL> select col1,add_months(col1,(-1*to_char(col1,'MM'))+1)
2 from (select to_date('10032007','DDMMYYYY') col1 from dual union all
3* select to_date('05012007','DDMMYYYY') col1 from dual )
SQL> /
COL1 ADD_MONT
10/03/07 10/01/07
05/01/07 05/01/07
SQL> Nicolas. -
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. -
Could any one please let me know how to get first day of a amonth?
Thanks in advance for your time!
MahbubThere's also...
DateAdd("m", DateDiff("m", #1/1/1900#, CurrentDate), #1/1/1900#)
Or if you want to write it directly in SQL Server...
SELECT DateAdd(mm, DateDiff(mm, 0, GetDate()), 0)
Jason -
Currency translation date fix on the first day of the month
Dear all,
is it possible to fixe one translation date per month that every transaction (goods income, purchase order, invoice, salesorder, payment,...) uses this exchange rate for booking?
The problem is, that this fixed exchange rate should only be valid for one company code in our SAP System. Therefore it is not possible to just change the rates in the SAP table TCURR.
Thank you very much in advance
Greetings
BerndHi Bernd,
We have had the same case with CZ and we choose to use alternative exchange rate in OBBS, and then created a new exchange rate type - but offcause then your company code should be equal to a specific currency.
Example, when your settings in OBA7 for document type NI points at exchang rate type M, and you have assigned Alternative exchange rate type CZKK for Type M for exchange rates from CZK to XXX, then the document will be booked with the alternative exchange rate.
Best regards
Pernille -
SQL select Statement -first day and last day of the month - 1 year from now
Hi,
I need to write a SQL to get the dates in between first day and last day of the month one year from now.
SELECT last_day(add_months(sysdate,12)) as lastday from dual
What could be the Query to get the first day of the month one year from now..
ie ..Sysdate - 3-DEC-2009
Result - 1-DEC-2010
thank youHi,
You can use TRUNC with 2 arguments to get the first DATE in a month, year, quarter, week, hour, minute, ISO year, ...
SELECT TRUNC ( ADD_MONTHS ( SYSDATE
, 12
, 'MONTH'
) AS first_of_month
FROM dual
;The DATE returned will be in the same month, year, quearter, ... as the first argument.
\We convered the last day of the month in [your previous question|http://forums.oracle.com/forums/message.jspa?messageID=3942939#3942939].
At that time, I warded about using LAST_DAY as a cutoff point; TRUNC is a much better way.
For example, to find all appointment_dates in the current month next year:
SELECT *
FROM appointments
WHERE appointment_date >= TRUNC (ADD_MONTHS (SYSDATE, 12), 'MONTH')
AND appointment_date < TRUNC (ADD_MONTHS (SYSDATE, 13), 'MONTH')Note that
the first part of the WHERE clause calls for dates on or equal to the beginning of the 12th month in the future, but
the second part of the WHERE clause calls for dates before, not equal to , the beginning of the 13th month in the future. -
Hi All,
In MYSQL any function is avaliable for get the FIRST DAY OF a month
LAST_DAY returns last day of the given date. Some thing like this?
Please adviceIn your ColdFusion code, an easy way to get the first day of the month would be along these lines:
<cfscript>
year = 2009;
month_number = 4;
if you don't want to/can't manually set the year and month you could do this
today = Now();
year = Year( today );
month_number = Month( today );
first_of_month = CreateDate( year,month_number,1 );
first_day_of_month = DayOfWeekAsString( first_of_month );
</cfscript>
The variable first_of_month will output April 1, 2009
The variable first_day_of_month will output Wednesday
If you're looking for something more specific to an issue in your application/code, please post some additional examples and details. -
Month end accrual posting date- Last day of the month
Hi Experts,
I have set up month end accruals for PY US by configuring posting dates, LDCD, WageType accrual processing class, Schema changes. I have also set the closing dates as the end of the month.
Now after I do the posting , there are three documents getting generated.
1. Accrual posting document with first day of the current month
2. Normal Payroll posting document with payroll period posting date
3. Accrual reversal document with first day of the following month.
My Question is: As per standard SAP configuration, the month end accrual will have first day of the month. Can we customize this to end of the month for doc#1 - accrual document?
Please do let me know your suggestion and ideas.
Thanks,
AmoshaHello,
I have a similar question and I hope to have more details on how to change the posting date.
The point is that I have an amount of 1200 and I have to post 100 for each month.
Key Date for Accruals: 31.01.2011
I posted 100 with Document date: 31.01.2011 and Posting date 31.01.2011
Key Date for Accruals: 28.01.2011
I posted 200 with Document date: 28.02.2011 and Posting date 28.02.2011
Also I reversed the amount posted in the previous month (100) with Document date: 31.01.2011 Posting date 28.02.2011
And so on...
The problem are the dates because I need to post the amount at the end of each month (28/02) and to reverse the previous amount at the beginning of the next month (01/02).
How can I change these dates?
Thanks a lot in advance
Kind Regards,
E. -
FM to get first date of the month
hi,
any FM to get first day of the month , lets say based on input 24.11.2008 , the FM would return 01.11.2008Do search in such case(Easy findings).
https://www.sdn.sap.com/irj/scn/advancedsearch?query=fmtogetfirstdayofthemonth&cat=sdn_all
Maybe you are looking for
-
Can't figure out how to enclose text in a rectangle, as I used to do in Word... any ideas?! thanks! Gary Eskow
-
Regarding Getting Error in Idoc .... Outbound table not found
Hello everyone I am working on ALE/Idoc, at the last i am getting error that idoc has created but cannot be send, I am using XML port (not file) so giving Physical Dictionary, please solve my problem where i have to change. please reply its urgent. T
-
Cannot bluetooth transfer with a sony ericsson Z710i
I bought a belkin USB bluetooth adapter for my laptop (running Tiger). It pairs and transfers files back and forth with my own sony phone but although it pairs with my wifes new Z701i it can't transfer a file to it saying it is unable to and there wa
-
SPAM, MSSQL, SAPKB70017
Hi all, I try to install SAPKB70017 in transaction SPAM. It gives me the following error: Post-import method MSS_SDBP_AFTER_IMP started for SDBP L, date and time: 20110316132447 Starting processing of SQL scripts (R3TR SDBP)... SQL script sap_delete_
-
SInce updating to iOS 8 I can no longer use the download all feature in iTunes Match. Only 25 tracks download and then the downloading stops and I have to click on each individual track to download the rest. Is anyone else having this problem? Can an