Get the number of the month
DB version: 10 gr 2I was asked to give a slow query performance.
I think that he is trying to get the number of months (as of June 6, July 7) after a few months to add logic. I replaced the column date with sysdate.
The query looks like
SELECT TO_NUMBER(TO_CHAR(ADD_MONTHS(TO_DATE('01-'||TO_CHAR(sysdate,'MON-RRRR'),'DD-MON-RRRR'),3),'MM')) from dual
Is there room for improvement?
Hello
What is
select EXTRACT(MONTH FROM sysdate) from dual;
Concerning
Peter
Tags: Database
Similar Questions
-
Is there one way other than to_char to get the month of the date field
Is there one way other than to_char to get the month of the date field
Hello
raj4tech wrote:
Is there one way other than to_char to get the month of the date field
EXTRACT is one:
SELECT INTERESTED (SYSDATE MONTHS) AS curr_month
DOUBLE;
-
get the month and year of date type
Hi all
I need to get the month and year of type date.
For example
Required result:select to_date('2011-01-17', 'yyyy-mm-dd') from dual;
Any ideas?01-2011
Thanks in advance,
Bahchevanov.select to_char(to_date('2011-01-17', 'yyyy-mm-dd'),'mm-yyyy') from dual;
HTH
-
How to get the month previous year?
Hello
I have to get the previous year three-months of the effective date, but I have a problem since the beginning of the year and it's because I set the incorrect query.
I mean:
I wrote this query
SELECT TO_CHAR(SYSDATE,'YYYYMM')-1, 2-TO_CHAR(SYSDATE,'YYYYMM'), TO_CHAR(SYSDATE,'YYYYMM')-3
FROM DUAL;
in order to get (on mars):
201502, 201501, 201412
but unfortunately, I get:
201502, 201501, 201500
Can you help me?
Thanks in advance!
Hello
Here's one way:
SELECT TO_CHAR (ADD_MONTHS (SYSDATE-1), "YYYYMM") AS the m1
, TO_CHAR (ADD_MONTHS (SYSDATE-2), "YYYYMM") AS m2
, TO_CHAR (ADD_MONTHS (SYSDATE,-3), "YYYYMM") M3
DOUBLE;
-
to get the month and year separated
Hello
I have the entry_date_fin of column (type of data-varchar2 (8))
with values like Apr.-2008
Feb-2009 etc.
can I get the distinct month and year separated
kindly guide mei tried select to_date(entry_date_fin,'MM') FROM xyz doesnt wrk
Although you are (wrongly, IMO) storage of dates as strings, just use string manipulation...
SQL> with t as (select 'FEB-2008' as txt from dual) 2 -- 3 select substr(txt,1,3) as mnth 4 ,substr(txt,5) as yr 5 from t 6 / MNT YR --- ---- FEB 2008 SQL>
-
Hello
I need to generate months between two bays. Last span should be up to sysmonth. I appreciate your time.
With the help of 10g or 11g
Required resultEFFECTIVE_MONTH DIST_ID SHOP_ID SHOP_NAME 01/01/2008 P00112 PFR00809 TOKEN GLASSES 06/01/2009 P00112 PFR00536 MAVALI GLASSES
EFFECTIVE_MONTH DIST_ID SHOP_ID SHOP_NAME SHOP_MONTH 1-Jan-2008 P00112 PFR00809 TOKEN GLASSES 1-Jan-2008 1-Jan-2008 P00112 PFR00809 TOKEN GLASSES 1-Feb-2008 1-Jan-2008 P00112 PFR00809 TOKEN GLASSES 1-Mar-2008 1-Jan-2008 P00112 PFR00809 TOKEN GLASSES 1-Apr-2008 1-Jan-2008 P00112 PFR00809 TOKEN GLASSES 1-May-2008 1-Jan-2008 P00112 PFR00809 TOKEN GLASSES 1-Jun-2008 1-Jan-2008 P00112 PFR00809 TOKEN GLASSES 1-Jul-2008 1-Jan-2008 P00112 PFR00809 TOKEN GLASSES 1-Aug-2008 1-Jan-2008 P00112 PFR00809 TOKEN GLASSES 1-Sep-2008 1-Jan-2008 P00112 PFR00809 TOKEN GLASSES 1-Oct-2008 1-Jan-2008 P00112 PFR00809 TOKEN GLASSES 1-Nov-2008 1-Jan-2008 P00112 PFR00809 TOKEN GLASSES 1-Dec-2008 1-Jan-2008 P00112 PFR00809 TOKEN GLASSES 1-Jan-2009 1-Jan-2008 P00112 PFR00809 TOKEN GLASSES 1-Feb-2009 1-Jan-2008 P00112 PFR00809 TOKEN GLASSES 1-Mar-2009 1-Jan-2008 P00112 PFR00809 TOKEN GLASSES 1-Apr-2009 1-Jan-2008 P00112 PFR00809 TOKEN GLASSES 1-May-2009 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Jun-2009 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Jul-2009 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Aug-2009 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Sep-2009 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Oct-2009 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Nov-2009 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Dec-2009 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Jan-2010 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Feb-2010 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Mar-2010 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Apr-2010 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-May-2010 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Jun-2010 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Jul-2010 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Aug-2010 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Sep-2010 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Oct-2010 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Nov-2010 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Dec-2010 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Jan-2011 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Feb-2011 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Mar-2011 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Apr-2011 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-May-2011 1-Jun-2009 P00112 PFR00536 MAVALI GLASSES 1-Jun-2011
Hello
Here's one way:
WITH got_month_cnt AS ( SELECT effective_month , dist_id , shop_id , shop_name , MONTHS_BETWEEN ( LEAD ( effective_month , 1 , ADD_MONTHS ( TRUNC (SYSDATE, 'MONTH') , 1 ) ) OVER ( PARTITION BY dist_id ORDER BY effective_month ) , effective_month ) AS month_cnt FROM table_x ) SELECT c.effective_month , c.dist_id, c.shop_id, c.shop_name , ADD_MONTHS ( c.effective_month , m.column_value - 1 ) AS shop_month FROM got_month_cnt c CROSS JOIN TABLE ( CAST ( MULTISET ( SELECT LEVEL FROM dual CONNECT BY LEVEL <= c.month_cnt ) AS sys.odcinumberlist ) ) m ;
I'm just guessing at what role (if any) dist_id, shop_id and shop_name play in this issue.
I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
Explain, using specific examples, how you get these results from these data.
Always tell what version of Oracle you are using.Published by: Frank Kulash, June 8, 2011 17:38
-
How to get the maximum number of days in a month?
How to get the maximum number of days in a month?
I use a dateField. where I can get the month. Now, I want to get the maximum number of days in a month.
How can I get it?
Please help me. and thanks in advance... []
NET. RIM. Device.API.util
Class DateTimeUtilitiesgetNumberOfDaysInMonth (int month, int year)
Returns the number of days in the specified monthIt took me like 10 seconds to find it in the API, I guess you spent more time writing the post...
-
getting the value of the month
How to get the month value, my intention is that I have to get the month, julian months using it gives values from 1 to 12, but my intention is I want January as a text when 1 is filled and so on. Could you suggest on this.
Thank you
OlivierDominique, try this in the default value field: ToChar (Today (), "MMMM")
You can replace the today() with the field variable or the variable you need.
Good luck
Thom -
Retrieve the month following the date
Hi people,
How can I get the part of months to a date.
Say, like, I want to get the month part (April = 4) 01/04/2009.
Thanks in advance!Hello
You can get all parts of a DATE using TO_CHAR.
For example, on April 1, 2009SELECT TO_CHAR (SYSDATE, 'Month') FROM dual;
product of the results of this
April
(if you use English) and
SELECT TO_CHAR (SYSDATE, 'MM') FROM dual;
produces this output (VARCHAR2)
04
-
Get the number of days in a month based on the month and year of fields
I have a column in my form which lists the days in a month. I want to configure a hidden field that calculates the total number of days in a month, based on the month and year of the field inputs. The number of days will determine what appears on the column. For example, if I put 4 months, and 2016 in the field of the year, I get 30 in the hidden field. Thus, on the column 'Day', I'll have numbers 1-30. Or if I put 2 months and 2016 in the field of the year, I get the 29 in the hidden field. If the numbers 1-29 appears in the column 'day '.
Found this on some forum javascript code:
//Month is 1 based
function daysInMonth(month,year) {
return new Date(year, month, 0).getDate();
}
//July
daysInMonth(7,2009); //31
//February
daysInMonth(2,2009); //28
daysInMonth(2,2008); //29I do not know how to convert this code in JavaScript to adobe and don't really know how to use it. All I know how to do is to configure the field values for the field month and year as variables. I am a novice programmer and would appreciate it really all the help I can get. Thank you in advance!
The code seems to be JavaScript and runs as needed by using the JavaScript console.
I would like to consider making more general code, so if you have a date string that includes at least the month and year we could just call the function and get the number of days for that month.
The following script will calculate the number of days in a month, by using at least the month and year values can display the result on the JavaScript console and all of the value field for the field that has this code as the custom calculation Script.
function daysInMonth (oDate) {}
return new Date (oDate.getFullYear (), oDate.getMonth () + 1, 0) .getDate ();
}nMonth var = this.getField("Month").valueAsString; get the value of month;
nYear var = this.getField("Year").valueAsString; get the value of the year;Event.Value = "";
If (nMonth! = "" & nYear!) = "") {}
var MyDate = util.scand ("' / mm/yyyy ', nMonth +" / "+ nYear); convert to date object;
var nDaysInMonth = daysInMonth (MyDate); get the number of days;Console.Open (); Open the JavaScript console;
Console.clear(); clear the console;
Console.println ("Days in" + nMonth + ":" + nDaysInMonth); show days in month;
Event.Value = nDaysInMonth; Set the value of the field;
}
-
Query help - to get the number of employees joined on each month regardless of the year
Hi all
I wrote the code below for number of employees joined each month regardless of the year of the employee table. But I couldn't get the result. Kindly help me where I'm wrong in my code,
Select to_char (hiredate, 'my') as join, count (empno) under the number
WCP
To_char Group (hiredate, 'my')
After having count (empno) > 1;
Your application displays the list of months (regardless of the year) where more than one employee was engaged with number of emplyees hired this month here. If you want months even if nobody was hired months thast, you emp table outer join to the list of every month:
with t as)
Select the level m
of the double
connect by level<=>=>
)
Select to_char (to_date (TM, 'mm'), 'my') Lun,
Count (e.empno) cnt
t
left join
E EMP
on Tahina = to_char (e.hiredate, 'mm')
Group of Tahina
order of Tahina
/
MY CNT
--- ----------
1 jan
February 2
Mar 0
Apr 2
May 2
1 Jun
July 0
August 0
2 sep
Oct 0
1 novMY CNT
--- ----------
Dec 312 selected lines.
SQL >
SY.
-
Get the number of days, months and year
Hi all
I'm using OBIEE 11 g. I have a line of dash for year (2010, 2011, etc.) and months (Jan, Feb,..., Dec). How can I get the number of days in a given month and year in my report?
For example, if I choose to Jan & 2011, I'd get 31 and 356. And if I choose Feb & 2011, I would get 28 and 356.
Thank you!I have something more good option here... Try to use this
DAYOFMONTH (TIMESTAMPADD (SQL_TSI_DAY, DAYOFMONTH (CURRENT_DATE) *-1, TIMESTAMPADD (SQL_TSI_MONTH, 1, CURRENT_DATE)))
This will give you the days for the month in progress (Oct 2011) after calculating the last day of each month... Similary dynamically pass the value Date or month... You will need to modify this function but shud be simple. Hope this helps :)
-
Get the number of months between the dates.
Hi I need to get the exact number of months between the dates. So if I'm Sysdate - to_date(31-JAN-2011) I should get something like 8.4 months. Months_between function doesn't quite give me what I need. Is it possible that I can do this?876056 wrote:
Hi I need to get the exact number of months between the dates. So if I'm Sysdate - to_date(31-JAN-2011) I should get something like 8.4 months. Months_between function doesn't quite give me what I need. Is it possible that I can do this?I don't see how you get 8.4 months. The counted months are February, March, April, may, June, July, August and, as of today, 9 and change the days of September. Unless I forgot the lessons of counting, I learned in kndergarten is 7 full months and a bit.
Maybe you want something like:
SQL> select months_between(Sysdate, to_date('01-JAN-2011', 'dd-mon-yyyy')) mb, 2 (Sysdate - to_date('01-JAN-2011', 'dd-mon-yyyy'))/30 div30 3 from dual; MB DIV30 ---------- ---------- 8.27800142 8.38726813
If you get the form date a table, you can use trunc (date_column, 'mm') at the date of the first day of the month.
John
-
is there an easy way to get the number of months in a year in a date range?
Hi, experts, I am a newbie.
are there any easy ways to get the number of months in a year in a date range?
I would like to write a user-defined function.
the input parameters are startdate, enddate, year
the output is a number, not a month.
for example, case 1
StartDate = 01032009 (DDMMYYYY)
end date = 28022010 (DDMMYYYY)
If the year 2009, the output is 10
If the year = 2010, the output is 2
case 2:
StartDate = 10032009 (DDMMYYYY)
end date = 15032010 (DDMMYYYY)
If the year 2009, the output is 10
If the year = 2010, the output is 3
Thank you very much!Hello
You can (also) try this:
SQL> with s as ( 2 ------------ Sample data ------------- 3 select to_date('01032009','ddmmyyyy') startdt, to_date('28022010','ddmmyyyy') enddt, 2009 yr from dual 4 union all 5 select to_date('01032009','ddmmyyyy') startdt, to_date('28022010','ddmmyyyy') enddt, 2010 yr from dual 6 union all 7 select to_date('10032009','ddmmyyyy') startdt, to_date('15032010','ddmmyyyy') enddt, 2009 yr from dual 8 union all 9 select to_date('10032009','ddmmyyyy') startdt, to_date('15032010','ddmmyyyy') enddt, 2010 yr from dual 10 ------------ Sample data ------------- 11 ) 12 select startdt, enddt, yr, 13 months_between( 14 least(trunc(to_date(yr+1,'yyyy'),'year') , add_months(trunc(enddt,'month'),1)) 15 , greatest(trunc(to_date(yr,'yyyy'),'year') , trunc(startdt,'month')) 16 ) nbmonths 17 from s; STARTDT ENDDT YR NBMONTHS ---------- ---------- ---------- ---------- 01/03/2009 28/02/2010 2009 10 01/03/2009 28/02/2010 2010 2 10/03/2009 15/03/2010 2009 10 10/03/2009 15/03/2010 2010 3
It's pretty simple. (no connection with, without functions SQL only integrated multicast, etc...)
-
How to get the name of the month of week number
Hi gurus,
I have week a year numbers.
I want to get the name of the month using the number of the week.
Is it possible to do this by using SQL.
Help, please.
Thank you
DominicSQL> var week number SQL> var year number SQL> SQL> begin 2 :year := 2007; 3 :week := 30; 4 end; 5 / PL/SQL procedure successfully completed. SQL> select to_char(trunc(to_date(:year,'yyyy'),'iyyy') + :week * 7, 'Month') month from dual 2 / MONTH --------- July SQL>
Maybe you are looking for
-
Used to install Aurora Firefox. installation interrupted
Hello. earlier today, I installed mozilla firefox, the stable version of the mozilla Web site. However, my intention was to install firefox aruora. so I uninstalled mozilla firefox and then install aurora. When it starts to install it stops and a mes
-
Motorcycle G version 2 - white color is sold out
Motorcycle G version 2 - white color is sold out. When will this be available? Thank you Vishal
-
OK, following touchpad problem...
Model: Acer Aspire E1-731-4699 OS: Windows 7 Ultimate OK... In a previous discussion, I had help to resolve a question relating to a problem of touchpad on my laptop. The driver disk that I burned embedded software with which Acer gave me contained
-
I can't get windows updates. Error 80070020.
Hi, please help me with my laptop. My last update 12/06/2012. It THEN Please HELP > I get error 80070020. I tried the clean restart. I tried the site you list in someone elses message with download of update problems but a different error code. None
-
Last download software HP C6280 hangs during installation on Windows 7
Someone else has the same problem? I wanted to get the functions scanner works again after the upgrade to Windows 7 from XP and the original installation CD no longer works. I downloaded the latest version of the software driver from HP's Support web