Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

first day of the month

Status
Not open for further replies.

ociruj

Programmer
Nov 8, 2002
22
PH
hi there,

how can i get the first day of a month? is there a function for that..?
 
Hi,

I do not think there is a function for it.

This one does last day of the Month so you can work out the first day of the month from it
Code:
select TO_CHAR(TO_DATE(TO_CHAR(ADD_MONTHS(SYSDATE, 1), 'MM') || '-01-' || TO_CHAR(ADD_MONTHS(SYSDATE, 1), 'YYYY'), 'MM-DD-YYYY')-1, 'dd-mm-yyyy') from dual;

Good luck


 
Ociruj,

I presume you want a function that returns the spelled day of the week of the first day of the month for a given date, is that correct? If so, here is the code for such a function:

create or replace function first_day (date_in in date) return varchar2 is
begin
return to_char(to_date('01'||to_char(date_in,'-mon-yy'),'dd-mon-yy'),'DAY');
end;
/
Function created.

select first_day(sysdate) from dual;

MONDAY

Is that what you wanted? If not, could you please clarify.

Dave
 
Oh, the answer is so easy :)

TRUNC(SYSDATE, 'MM') - the first day of current month

LAST_DAY(SYSDATE)+1 - the first day of the next month


Regards, Dima
 
Thanks DIMA for your help.... Regards...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top