dbTalk Databases Forums  

trunc year

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss trunc year in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
muhammaddzulkarnain@gmail.com
 
Posts: n/a

Default trunc year - 10-23-2008 , 05:15 AM






Below is to get date range between a month

SQL> select sysdate,
2 trunc(add_months(sysdate,-1),'month') start_date,
3 trunc(sysdate,'month')-1 end_date
4 from dual;
SYSDATE START_DATE END_DATE
---------- ---------- ----------
21/10/2008 01/09/2008 30/09/2008



how to get date range between a year?

start_date = 20080101
end_date = 20081231

Reply With Quote
  #2  
Old   
gym dot scuba dot kennedy at gmail
 
Posts: n/a

Default Re: trunc year - 10-23-2008 , 05:45 AM







<muhammaddzulkarnain (AT) gmail (DOT) com> wrote

Quote:
Below is to get date range between a month

SQL> select sysdate,
2 trunc(add_months(sysdate,-1),'month') start_date,
3 trunc(sysdate,'month')-1 end_date
4 from dual;
SYSDATE START_DATE END_DATE
---------- ---------- ----------
21/10/2008 01/09/2008 30/09/2008



how to get date range between a year?

start_date = 20080101
end_date = 20081231
select
to_date(to_char(sysdate,'yyyy')||'0101','yyyymmdd' ),
to_date(to_char(sysdate,'yyyy')||'1231','yyyymmdd' ) from dual;
since the first day and the last day of a year are always the same month and
day.
If you want the whole year then (and not ending midnight of 12/31 then end
date

select
to_date(to_char(sysdate,'yyyy')||'0101','yyyymmdd' ),
to_date(to_char(sysdate+366,'yyyy'))||'0101','yyyy mmdd') from dual;




Reply With Quote
  #3  
Old   
gym dot scuba dot kennedy at gmail
 
Posts: n/a

Default Re: trunc year - 10-23-2008 , 05:45 AM




<muhammaddzulkarnain (AT) gmail (DOT) com> wrote

Quote:
Below is to get date range between a month

SQL> select sysdate,
2 trunc(add_months(sysdate,-1),'month') start_date,
3 trunc(sysdate,'month')-1 end_date
4 from dual;
SYSDATE START_DATE END_DATE
---------- ---------- ----------
21/10/2008 01/09/2008 30/09/2008



how to get date range between a year?

start_date = 20080101
end_date = 20081231
select
to_date(to_char(sysdate,'yyyy')||'0101','yyyymmdd' ),
to_date(to_char(sysdate,'yyyy')||'1231','yyyymmdd' ) from dual;
since the first day and the last day of a year are always the same month and
day.
If you want the whole year then (and not ending midnight of 12/31 then end
date

select
to_date(to_char(sysdate,'yyyy')||'0101','yyyymmdd' ),
to_date(to_char(sysdate+366,'yyyy'))||'0101','yyyy mmdd') from dual;




Reply With Quote
  #4  
Old   
gym dot scuba dot kennedy at gmail
 
Posts: n/a

Default Re: trunc year - 10-23-2008 , 05:45 AM




<muhammaddzulkarnain (AT) gmail (DOT) com> wrote

Quote:
Below is to get date range between a month

SQL> select sysdate,
2 trunc(add_months(sysdate,-1),'month') start_date,
3 trunc(sysdate,'month')-1 end_date
4 from dual;
SYSDATE START_DATE END_DATE
---------- ---------- ----------
21/10/2008 01/09/2008 30/09/2008



how to get date range between a year?

start_date = 20080101
end_date = 20081231
select
to_date(to_char(sysdate,'yyyy')||'0101','yyyymmdd' ),
to_date(to_char(sysdate,'yyyy')||'1231','yyyymmdd' ) from dual;
since the first day and the last day of a year are always the same month and
day.
If you want the whole year then (and not ending midnight of 12/31 then end
date

select
to_date(to_char(sysdate,'yyyy')||'0101','yyyymmdd' ),
to_date(to_char(sysdate+366,'yyyy'))||'0101','yyyy mmdd') from dual;




Reply With Quote
  #5  
Old   
gym dot scuba dot kennedy at gmail
 
Posts: n/a

Default Re: trunc year - 10-23-2008 , 05:45 AM




<muhammaddzulkarnain (AT) gmail (DOT) com> wrote

Quote:
Below is to get date range between a month

SQL> select sysdate,
2 trunc(add_months(sysdate,-1),'month') start_date,
3 trunc(sysdate,'month')-1 end_date
4 from dual;
SYSDATE START_DATE END_DATE
---------- ---------- ----------
21/10/2008 01/09/2008 30/09/2008



how to get date range between a year?

start_date = 20080101
end_date = 20081231
select
to_date(to_char(sysdate,'yyyy')||'0101','yyyymmdd' ),
to_date(to_char(sysdate,'yyyy')||'1231','yyyymmdd' ) from dual;
since the first day and the last day of a year are always the same month and
day.
If you want the whole year then (and not ending midnight of 12/31 then end
date

select
to_date(to_char(sysdate,'yyyy')||'0101','yyyymmdd' ),
to_date(to_char(sysdate+366,'yyyy'))||'0101','yyyy mmdd') from dual;




Reply With Quote
  #6  
Old   
sybrandb@hccnet.nl
 
Posts: n/a

Default Re: trunc year - 10-23-2008 , 11:22 AM



On Thu, 23 Oct 2008 03:15:36 -0700 (PDT),
muhammaddzulkarnain (AT) gmail (DOT) com wrote:

Quote:
Below is to get date range between a month

SQL> select sysdate,
2 trunc(add_months(sysdate,-1),'month') start_date,
3 trunc(sysdate,'month')-1 end_date
4 from dual;
SYSDATE START_DATE END_DATE
---------- ---------- ----------
21/10/2008 01/09/2008 30/09/2008



how to get date range between a year?

start_date = 20080101
end_date = 20081231
A year is 12 months. last_day(add_months..) should do it.
Those functions are documented in the SQL refernence manual under
'Date functions' please read it!!!

--

Sybrand Bakker
Senior Oracle DBA


Reply With Quote
  #7  
Old   
sybrandb@hccnet.nl
 
Posts: n/a

Default Re: trunc year - 10-23-2008 , 11:22 AM



On Thu, 23 Oct 2008 03:15:36 -0700 (PDT),
muhammaddzulkarnain (AT) gmail (DOT) com wrote:

Quote:
Below is to get date range between a month

SQL> select sysdate,
2 trunc(add_months(sysdate,-1),'month') start_date,
3 trunc(sysdate,'month')-1 end_date
4 from dual;
SYSDATE START_DATE END_DATE
---------- ---------- ----------
21/10/2008 01/09/2008 30/09/2008



how to get date range between a year?

start_date = 20080101
end_date = 20081231
A year is 12 months. last_day(add_months..) should do it.
Those functions are documented in the SQL refernence manual under
'Date functions' please read it!!!

--

Sybrand Bakker
Senior Oracle DBA


Reply With Quote
  #8  
Old   
sybrandb@hccnet.nl
 
Posts: n/a

Default Re: trunc year - 10-23-2008 , 11:22 AM



On Thu, 23 Oct 2008 03:15:36 -0700 (PDT),
muhammaddzulkarnain (AT) gmail (DOT) com wrote:

Quote:
Below is to get date range between a month

SQL> select sysdate,
2 trunc(add_months(sysdate,-1),'month') start_date,
3 trunc(sysdate,'month')-1 end_date
4 from dual;
SYSDATE START_DATE END_DATE
---------- ---------- ----------
21/10/2008 01/09/2008 30/09/2008



how to get date range between a year?

start_date = 20080101
end_date = 20081231
A year is 12 months. last_day(add_months..) should do it.
Those functions are documented in the SQL refernence manual under
'Date functions' please read it!!!

--

Sybrand Bakker
Senior Oracle DBA


Reply With Quote
  #9  
Old   
sybrandb@hccnet.nl
 
Posts: n/a

Default Re: trunc year - 10-23-2008 , 11:22 AM



On Thu, 23 Oct 2008 03:15:36 -0700 (PDT),
muhammaddzulkarnain (AT) gmail (DOT) com wrote:

Quote:
Below is to get date range between a month

SQL> select sysdate,
2 trunc(add_months(sysdate,-1),'month') start_date,
3 trunc(sysdate,'month')-1 end_date
4 from dual;
SYSDATE START_DATE END_DATE
---------- ---------- ----------
21/10/2008 01/09/2008 30/09/2008



how to get date range between a year?

start_date = 20080101
end_date = 20081231
A year is 12 months. last_day(add_months..) should do it.
Those functions are documented in the SQL refernence manual under
'Date functions' please read it!!!

--

Sybrand Bakker
Senior Oracle DBA


Reply With Quote
  #10  
Old   
Michel Cadot
 
Posts: n/a

Default Re: trunc year - 10-23-2008 , 12:00 PM




<muhammaddzulkarnain (AT) gmail (DOT) com> a écrit dans le message de news:
e4851241-fa80-40ea-8052-9acb883a8d85...oglegroups.com...
Quote:
Below is to get date range between a month

SQL> select sysdate,
2 trunc(add_months(sysdate,-1),'month') start_date,
3 trunc(sysdate,'month')-1 end_date
4 from dual;
SYSDATE START_DATE END_DATE
---------- ---------- ----------
21/10/2008 01/09/2008 30/09/2008



how to get date range between a year?

start_date = 20080101
end_date = 20081231
See answers to your question at:
http://www.orafaq.com/forum/t/126566/102589/

Regards
Michel




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.