Home » SQL & PL/SQL » SQL & PL/SQL » First day
First day [message #11225] Mon, 15 March 2004 00:48 Go to next message
Kader
Messages: 5
Registered: January 2002
Junior Member
Hi Pauls,

 How to find out the first day of particular month like last_day function?

Thanks

 
Re: First day [message #11226 is a reply to message #11225] Mon, 15 March 2004 01:15 Go to previous messageGo to next message
Rishi
Messages: 63
Registered: January 2001
Member
SQL> select add_months(last_day(sysdate),-1) + 1
from dual;

Replace sysdate variable by the date whose first day of month u want to know...

eg:-

select add_months(last_day('29/02/2004'),-1) + 1
from dual;

this will display result as 01/02/2004 if the nls_date_format is set as 'dd/mm/yyyy'

Regards
Rishi
Re: First day [message #11227 is a reply to message #11225] Mon, 15 March 2004 01:21 Go to previous messageGo to next message
Vishal
Messages: 86
Registered: August 2000
Member
why do so much labour when we have TRUNC function for this thing.....
Re: First day [message #11228 is a reply to message #11226] Mon, 15 March 2004 01:23 Go to previous messageGo to next message
Vishal
Messages: 86
Registered: August 2000
Member
why do so much labour when we have TRUNC function for this thing.....
Re: First day [message #11230 is a reply to message #11227] Mon, 15 March 2004 01:44 Go to previous messageGo to next message
Rishi
Messages: 63
Registered: January 2001
Member
Hi Vishal

I have'nt used the Trunc function.

If possible could you please give the query for the same.

It would be helpful to me if can do it some other way around as suggested by you.

Rishi
Re: First day [message #11234 is a reply to message #11230] Mon, 15 March 2004 02:05 Go to previous messageGo to next message
Vishal
Messages: 86
Registered: August 2000
Member
TRUNC takes u to start depending on the 2nd parameter -
select trunc(sysdate,'month') from dual;
will give u start of the month
Similarly
select trunc(sysdate,'year') from dual;
will give u start of the year

see TRUNC documentation for more details.
Re: First day [message #11241 is a reply to message #11228] Mon, 15 March 2004 07:52 Go to previous message
pallavi
Messages: 14
Registered: April 2001
Junior Member
hi,

have one more way to find out first day.
check outif u can use it.

select '01-'||to_char(sysdate,'MON-RR') from dual;
Previous Topic: procedue for finding clash (urgent)
Next Topic: How to Batch Insert ?
Goto Forum:
  


Current Time: Thu Apr 25 19:16:02 CDT 2024