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;
Thanks
Hi,
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
Similar Messages
-
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. -
For the previous month first day and last day
i want to schedule my reports from the last month first date to last month last date.
any body have queries for the while scheduling to uuse it.
Ex:sysdate() - today's date
first_day_of_month()- first day of current month
first day of last month ---?
last day of the last month ---?In the parameter, put this
{$FIRST_DAY_OF_MONTH()$}other values you can use in default parameter values are
{$SYSDATE()$} - to get current date
{$FIRST_DAY_OF_MONTH()$} - to get first day of the current month
{$FIRST_DAY_OF_YEAR()$} - to get first day of the current year
{$LAST_DAY_OF_MONTH()$} - to get last day of the current month
{$LAST_DAY_OF_YEAR()$} - to get last day of the current year
Re: Default date as first of month
TO get last day of last month
{$FIRST_DAY_OF_MONTH()-1$}You can add/subtract number with these functions and no other functions are available. -
Query for back 2nd motnh first day and last day
Any body please provide me the query for back 2nd month first day to back 2nd month last day?
last month first day
TIMESTAMPADD(SQL_TSI_MONTH,-1, TIMESTAMPADD(SQL_TSI_DAY, -(DAY(CURRENT_DATE)-1), CURRENT_DATE))
last month last day
TIMESTAMPADD(SQL_TSI_DAY, -(DAY(CURRENT_DATE)), CURRENT_DATE)
anyone please provide me the queries for previous months like above queries?
2nd back month first day --?
2nd back month last day--?
3rd back month first day --?
3rd back month last day --?Hi,
Check with this...
Previous month last day -
TIMESTAMPADD(SQL_TSI_DAY, DAYOFMONTH(CURRENT_DATE)*-1, CURRENT_DATE)
Last day of 2nd month -
TIMESTAMPADD(SQL_TSI_MONTH,-1,TIMESTAMPADD(SQL_TSI_DAY, DAYOFMONTH(CURRENT_DATE)*-1, CURRENT_DATE))
Last day of 3rd month -
TIMESTAMPADD(SQL_TSI_MONTH,-2,TIMESTAMPADD(SQL_TSI_DAY, DAYOFMONTH(CURRENT_DATE)*-1, CURRENT_DATE))
(OR)
Previous month last day -
TIMESTAMPADD(SQL_TSI_DAY, DAYOFMONTH(CURRENT_DATE)*-1, CURRENT_DATE)
Last day of 2nd month -
TIMESTAMPADD(SQL_TSI_DAY,DAYOFMONTH(TIMESTAMPADD(SQL_TSI_DAY, DAYOFMONTH(CURRENT_DATE)*-1, CURRENT_DATE))*-1,TIMESTAMPADD(SQL_TSI_DAY, DAYOFMONTH(CURRENT_DATE)*-1, CURRENT_DATE))
Last day of 3rd month -
TIMESTAMPADD(SQL_TSI_DAY, DAYOFMONTH(TIMESTAMPADD(SQL_TSI_DAY,DAYOFMONTH(TIMESTAMPADD(SQL_TSI_DAY, DAYOFMONTH(CURRENT_DATE)*-1, CURRENT_DATE))*-1,TIMESTAMPADD(SQL_TSI_DAY, DAYOFMONTH(CURRENT_DATE)*-1, CURRENT_DATE)))*-1,TIMESTAMPADD(SQL_TSI_DAY,DAYOFMONTH(TIMESTAMPADD(SQL_TSI_DAY, DAYOFMONTH(CURRENT_DATE)*-1, CURRENT_DATE))*-1,TIMESTAMPADD(SQL_TSI_DAY, DAYOFMONTH(CURRENT_DATE)*-1, CURRENT_DATE)))
Regards,
Srikanth -
FM for getting First name and last name in HR
Dear all,
can anyone tell me the Functrion module for getting <b>first name</b> and <b>last name</b> in HR.
Regards,
VineelHi Vineel,
Use FM
<b> HRWPC_GET_EMPLOYEE_NAME</b>
<b> HR_TMW_GET_EMPLOYEE_NAME</b>
Reward points if helpful.
Regards,
Hemant -
Get First and last day of Month..
Hi Friends,
I am trying to fetch First and Last day of a month and would like to implement that in the following code:
SELECT COALESCE(Date_A, Date_B, Date_C)
FROM dual
Here Date A and B are in Format of MM DD YYYY (March 14, 2008)
and Date C is like MM YYYY (March 2008)
How can I get the Date_C as March 1, 2008 OR March 31, 2008 format if Date A and B are NULL ?
Thanks!
Edited by: user11095386 on Apr 23, 2009 10:45 AMHi,
In my earlier message, I thought that you were starting with strings like '03 12 2009' and that you wanted to display them as 'March 12 2009'. If what you have is just the reverse, then just reverse the format strings in my first message. Add a comma, if you want one, in the appropriate format string.
I believe this is what you want:
COALESCE ( TO_CHAR ( TO_DATE ( Date_A, 'fmMonth DD YYYY'), 'MM DD YYYY')
, TO_CHAR ( TO_DATE ( Date_B, 'fmMonth DD YYYY'), 'MM DD YYYY')
, TO_CHAR ( TO_DATE ( Date_C, 'fmMonth YYYY'), 'MM DD YYYY')
)Notice how, on the 3rd line, TO_DATE is called without DD in the format string:
TO_DATE ( Date_C, 'fmMonth YYYY')When you do this, the day defaults to the 1st of the month, so this is all you have to do to convert the VARCHAR2 'March 2009' to the DATE 01-Mar-2009.
If you want the last day of the month, not the first, when Date_C is chosen, then use LAST_DAY:
COALESCE ( TO_CHAR ( TO_DATE ( Date_A, 'fmMonth DD YYYY'), 'MM DD YYYY')
, TO_CHAR ( TO_DATE ( Date_B, 'fmMonth DD YYYY'), 'MM DD YYYY')
, TO_CHAR ( LAST_DAY ( TO_DATE ( Date_C
, 'fmMonth YYYY'
, 'MM DD YYYY'
) -
Get first and last day given month name with combobox
hi guys ;
I loaded to month name in combobox and I want to get first and last day by the name of month from selected Combobox
So if I select to february than results get 01.02.2015 and 28.02.2015
if select March than 01.03.2015 and 31.03.2015
Thanks .Thank you for useful post , How to change Culturinfo as a Turkish Month name ?
your's code is work if I use English month name But it was get error when use the turkish month name
If you are running your application on a Turkish Windows you could use the System.Globalization.CultureInfo.CurrentCulture:
int month = DateTime.ParseExact(monthName, "MMMM", System.Globalization.CultureInfo.CurrentCulture).Month;
Or you could use create an explicit culture object like this:
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("tr-TR");
int month = DateTime.ParseExact(monthName, "MMMM", ci).Month;
Please remember to mark all helpful posts as answer to close your threads. -
Getting first and last day of week
Dear all .
Is there any funcion module which gives first and last day of the current week .
Eg . todays day is 15.11.2006
start date of week : 13.11.2006
end date of week : 19.11.2006
in the same way I want how many days are there in month .
Eg : for Nov month :
30 days .
for dec month 31 days .
Thank you in advanceUse FM GET_WEEK_INFO_BASED_ON_DATE
Import parameters Value
DATE 15.11.2006
Export parameters Value
WEEK 200646
MONDAY 13.11.2006
SUNDAY 19.11.2006
Use FM HR_E_NUM_OF_DAYS_OF_MONTH
Import parameters Value
P_FECHA 15.11.2006
Export parameters Value
NUMBER_OF_DAYS 30
I hope it helps.
Best Regards,
Vibha
*Please mark all the helpful answers -
Need the first day of the year and last day of the year.
hi all,
i need a function module which can get me the first day of current year and last day of the current year??
please help.Similar date questions are being asked ALL THE TIME. Please search.
-
How to find first and last day of last month?.
Hello,
I am using Crystal Report XI.
Reports will be generated on first of every month for
previous month. I want to find start and end date of previous month
dynamic.
For august, Start date is July 1st and End date July 31st.
For September, start date is Aug 1st and Aug 31st.
How can i get first of previous month as start date and last
day of the previous month as end date?.
Same kind of thing I want to do for future report ..find next
month start date and end date.
ThanksAdomacro,
you could do a function, like this
<cffunction name="getReportdates" returntype="struct"
hint="Given an arbitrary month and year, the function returns a
structure containing the first and last day of the previous
month">
<!--- Take current month and current year as the default
--->
<cfargument name="mnth" type="string" required="No"
default="#monthAsString(month(now()))#">
<cfargument name="yr" type="numeric" required="No"
default="#year(now())#">
<cfset firstDayOfGivenMonth = parseDateTime("1 " &
arguments.mnth & " #arguments.yr#")>
<cfset lastDayOfPreviousMonth =
dateAdd("d",-1,firstDayOfGivenMonth)>
<cfset numberOfDaysOfPreviousMonth =
daysInMonth(lastDayOfPreviousMonth)>
<cfset firstDayOfPreviousMonth =
dateAdd("d",-#numberOfDaysOfPreviousMonth#,firstDayOfGivenMonth)>
<cfset reportDates = structNew()>
<cfset reportDates.firstDayOfPreviousMonth =
firstDayOfPreviousMonth>
<cfset reportDates.lastDayOfPreviousMonth =
lastDayOfPreviousMonth>
<cfreturn reportDates>
</cffunction>
<!--- Example usage --->
<p>
Given month: <strong>March
2004</strong><br>
begin date:
<cfoutput>#dateFormat(getReportdates('March',2004).firstDayOfPreviousMonth,"d
mmm yyyy")#</cfoutput><br>
end date:
<cfoutput>#dateFormat(getReportdates('March',2004).lastDayOfPreviousMonth,"d
mmm yyyy")#</cfoutput><br>
</p>
<p>
Given month: <strong>August
2007</strong><br>
begin date:
<cfoutput>#dateFormat(getReportdates('August',2007).firstDayOfPreviousMonth,"d
mmm yyyy")#</cfoutput><br>
end date:
<cfoutput>#dateFormat(getReportdates('August',2007).lastDayOfPreviousMonth,"d
mmm yyyy")#</cfoutput><br>
</p> -
How to find first and last day of previous month?.
Based on current month, I want to find start and end day of
previous month.
For example,
For august, Start date is July 1st and End date July 31st.
How can i get first of previous month as start date and last
day of the previous month as end date?.
Same way,
i want to find start date of current month and end date of
next month.
Example:
For august,
i want to get start date, august 1st and end date : september
30.
How can i do this from current date or now().
I am looking for best and easy way to find start and end
dates..
Thanks<cfset today = now()>
<cfset firstOfThisMonth = createDate(year(today),
month(today), 1)>
<cfset lastOfNextMonth = dateAdd("d", -1, dateAdd("m", 2,
firstOfThisMonth))>
<cfoutput>
today = #today#<br>
firstOfThisMonth = #firstOfThisMonth#<br>
lastOfNextMonth = #lastOfNextMonth#<br>
</cfoutput>
Edit - To find the start and end day of previous month, get
the first of THIS month. Use Subtract 1 month ("m") to get the
start date. Subtract 1 day ("d") to get the end date. -
Find the first and last day of week giving a certain date
Hi,
i have an application in wich the user puts a date, say today 2010-08-10 and i have to calculate first and last day of that week, in this case 2010-08-09 and 2010-08-15. How can i do this?
Many thanks in advance,
Nuno Almeidanfalmeida wrote:
i have an application in wich the user puts a date, say today 2010-08-10 and i have to calculate first and last day of that week, in this case 2010-08-09 and 2010-08-15. How can i do this?First step is being sure that you know what a 'week' is.
For example does it really start on monday? And will it always start on monday?
And what day does the 'week' end on for 2010-12-29? In some businesses it will end on 2010-12-31 (friday) -
Get first and last date of month
Hi,
Is there any function module to get first and last date of month for a entered date.
Please let me know.
Regards,
SPHi,
Use the below FM to find the Last day of month and them u can easily calculate the first day.
DATA : v_startdate TYPE sy-datum.
DATA : v_enddate TYPE sy-datum.
DATA : v_temp TYPE dats.
v_temp = sy-datum.
CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
EXPORTING
day_in = v_temp
IMPORTING
last_day_of_month = v_enddate
CONCATENATE v_enddate+0(6) '01' INTO v_startdate.
Hope it helps.
Regards,
Arnab. -
Day must be between 1 and last day of month
Hi
I have a master detail form for overtime entries.
Master Block contain emp_no,name,month etc.
Detail block contain a date field ,,from time, to time etc
when i enter the date in detail block it defaults the month from Server date and i am getting the error "Day must be between 1 and last day of ...."
The form is going to reside on server so i cant go for changing system date for that.
THe work around i am trying is i have created a dummy item in detail block for Date(dd) entry and populating my original date field on the basis of it.
so that i can get rid of last day validation of month.The datatype of dummy item is char
my code is
c_day varchar(2);
c_month varchar(2);
c_year varchar(4);
d_date varchar(8);
begin
c_day := :DETAIL.dummy;
c_month := to_char(:MASTER.month, 'mm');
c_year := to_char(:master.month, 'yyyy');
d_date := c_day||c_month||c_year;
:DETAIL.ot_date := to_date(d_date,'ddmmyyyy');
end;
I am using post change trigger on my dummy item but i am getting ORA-01840 for that.I have tried several ways but it is giving different type of date errors for that.
Any help is highly appreciatedDear try this
SELECT RUN_NUM, CV AS MONTH_DATE
FROM
SELECT ROWNUM AS RUN_NUM,TO_DATE('01-' || 'SEP' || '-' || 2007 ,'DD/MM/YYYY')+ (ROWNUM-1) CV
FROM
(SELECT 1 FROM DUAL GROUP BY CUBE (1,1,1,1,1)) A
WHERE TO_CHAR(CV,'MON-YYYY') = 'SEP-2007' -
Error: ORA-01847: day of month must be between 1 and last day of month
Hi,
I am getting this ORA-01847: day of month must be between 1 and last day of month type of error but I have checked my data all are correct.
I am inserting the data in the merge query. It is giving the above error.
but when i insert the data like that
insert into dt(start_date) select TO_DATE (tariff_start_date, 'DD/MM/RRRR') from ext_zpp0a871;
It does not give any error.
Please find the below code
DECLARE
l_sv_error_msg VARCHAR2 (1000);
BEGIN
FOR i IN (SELECT condition_type, sales_org, division_channel, division,
price_list, ean_upc, amount, unit_of_measure1,
tariff_start_date, tariff_end_date
FROM ext_zpp0a871--This is external table
WHERE condition_type = 'ZPP0' AND ROWNUM < 200)
LOOP
BEGIN
MERGE INTO sap_tariff st
USING (SELECT i.price_list pl, i.ean_upc upc,
TO_DATE (i.tariff_start_date, 'DD/MM/RRRR') tsd,
TO_DATE (i.tariff_end_date, 'DD/MM/RRRR') ted
FROM DUAL) du
ON (st.prod_ean_cuni = du.upc
AND st.pricelist = du.pl
AND st.tariff_start_date = du.tsd
AND st.tariff_end_date = du.ted)
WHEN MATCHED THEN
UPDATE
SET st.condition_type = i.condition_type,
st.sales_org = i.sales_org,
st.division_channel = i.division_channel,
st.division = i.division,
st.amount =
TO_NUMBER (REPLACE (REPLACE (i.amount, '.', NULL),
st.uom = i.unit_of_measure1
WHEN NOT MATCHED THEN
INSERT (condition_type, sales_org, division_channel, division,
pricelist, prod_ean_cuni, amount, uom,
tariff_start_date, tariff_end_date)
VALUES (i.condition_type, i.sales_org, i.division_channel,
i.division, i.price_list, i.ean_upc,
TO_NUMBER (REPLACE (REPLACE (i.amount, '.', NULL),
i.unit_of_measure1,
TO_DATE (i.tariff_start_date, 'DD/MM/RRRR'),
TO_DATE (i.tariff_end_date, 'DD/MM/RRRR'));
/*INSERT INTO sap_tariff
(condition_type, sales_org, division_channel,
division, pricelist, prod_ean_cuni,
amount,
uom,
tariff_start_date,
tariff_end_date
VALUES (i.condition_type, i.sales_org, i.division_channel,
i.division, i.price_list, i.ean_upc,
TO_NUMBER (REPLACE (REPLACE (i.amount, '.', NULL),
i.unit_of_measure1,
TO_DATE (i.tariff_start_date, 'DD/MM/RRRR'),
TO_DATE (i.tariff_end_date, 'DD/MM/RRRR')
EXCEPTION
WHEN DUP_VAL_ON_INDEX
THEN
UPDATE sap_tariff
SET condition_type = i.condition_type,
sales_org = i.sales_org,
division_channel = i.division_channel,
division = i.division,
amount =
TO_NUMBER (REPLACE (REPLACE (i.amount, '.', NULL),
uom = i.unit_of_measure1;
WHEN OTHERS
THEN
l_sv_error_msg := SQLERRM (SQLCODE);
INSERT INTO sap_tariff_log
(date_of_load, condition_type, sales_org,
division_channel, division, price_list,
prod_ean_cuni, amount, uom,
tariff_start_date, tariff_end_date,
rejection_reason
VALUES (SYSDATE, i.condition_type, i.sales_org,
i.division_channel, i.division, i.price_list,
i.ean_upc, i.amount, i.unit_of_measure1,
i.tariff_start_date, i.tariff_end_date,
l_sv_error_msg
END;
END LOOP;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
l_sv_error_msg := SQLERRM (SQLCODE);
neo_pro_log ('Others Error', l_sv_error_msg);
END;user13400510 wrote:
but when i insert the data like that
insert into dt(start_date) select TO_DATE (tariff_start_date, 'DD/MM/RRRR') from ext_zpp0a871;
It does not give any error.Maybe the error is on tariff_end_date instead of tariff_start_date ?
What are the datatypes of tariff_start_date and tariff_end_date ? If they are already dates, and you to_date them (and depending on what your nls_date_xxxxx params are) you can have such errors :SQL> sho parameter nls_date_format
NAME_COL_PLUS_SHOW_PARAM TYPE VALUE_COL_PLUS_SHOW_PARAM
nls_date_format string DD/MM/YYYY
SQL> select to_date(sysdate,'Day dd Mon RRRR') from dual;
select to_date(sysdate,'Day dd Mon RRRR') from dual
ERROR at line 1:
ORA-01846: not a valid day of the week
SQL> select to_date(sysdate,'hh24:mi:ss dd/mm/rrrr') from dual;
select to_date(sysdate,'hh24:mi:ss dd/mm/rrrr') from dual
ERROR at line 1:
ORA-01850: hour must be between 0 and 23
Maybe you are looking for
-
Iphone 4 camera flash not working.
Iphone 4 camera flash not working when taking pictures but works with the flashlight app. I have ios 7. Tried factory reset. My wife has the same problem with her iphone 4 since the first month she has had it. Any suggestions?
-
When I put a burned cd from one Mac into another Mac, song titles do not show up! I have to enter them manually! My CD player reads the titles that i on the cd; how can I get my Mac to do so?
-
Notes Enable fails with Active Sync
We are using the Sun IdM 6.0. we using the oracle database table as a authoritative source.we have configured the Active sync to keep polling for any change in the "status" attribute in database table. With the status attribute "0", it disables user
-
Basic CFC not binding to s:DataGrid
Installed "FB Burrito". OK. Following this tutorial. http://www.adobe.com/devnet/flex/articles/fcf_getting_started_coldfusion_flex.html (but with default hero 4.5 sdk) CFC introspects fine defined return datatype. OK. Drag a DataGrid to design-view
-
Hi all, I used SBO 2005A SP1 PL 43. I intend to import setting, e.g I have one company (A) and will create a new company (B). How to import setting company (A) ---> only setting but not database A -- into B? So company B has the same as setting confi