First day of the month
How to find the first day of the month if the month format is like TO_CHAR(SYSDATE,'YYYYMM')
Sanjay
Published by: user12957777 on May 23, 2012 21:12
There is no 'day' in this date format.
What you trying to do? What do you expect the result to look like?
Are you wanting to set a date for the first day of the month and year of your example?
SELECT TO_DATE(TO_CHAR(SYSDATE,'YYYYMM') || '01', 'YYYYMMDD') FROM DUAL;
Tags: Database
Similar Questions
-
How to calculate the first day of the month following in BI Publisher
I need to be able to calculate the first day of the month of a date field in a BI Publisher model. The field name is COL_CLM_180 and contains a date in the format "YYYY-MM-DD". I have found so far any documentation that still gives me an idea of what to do.
Any help or advice would be appreciated
Hi - thank you very much for your help. Your last answer got me going in the right direction and I indeed was dense. I don't know why I don't think to the calculation in the original query. I put the statement: TRUNC (ADD_MONTHS(A.COL_CLM_180,1), 'MM') in a column in the query of conduct and it has worked flawlessly. Thank you - thank you - thank you.
-
query for the first day of the month
Hi all
How to get the first day of the month in the sql query.
SQL> select trunc(sysdate,'mm') first_day from dual; FIRST_DAY --------- 01-AUG-15 SQL> select trunc(sysdate,'month') first_day from dual; FIRST_DAY --------- 01-AUG-15 SQL> select trunc(sysdate,'mon') first_day from dual; FIRST_DAY --------- 01-AUG-15 SQL>
-
How to find the first day of the month following two years one year from now?
Hello
I need to find the first day of the month following two years ago, based on the current date.
For example: If today is the 31/08/2015 so I need to find the date range between 31/08/2015 and on 09/01/2013. How can I write an SQL which allows to automate this calculation instead of hard-coding the values. Please do help me out with this so that I can build the SQL that can produce the desired result.
Thank you
Dhilip
find the start of the month - 2 years in advance, early - 2 years + 1 months in advance and go back 1
Select trunc (add_months(sysdate,24), 'MM'), trunc (add_months(sysdate,25), 'MM') - 1 double;
-
first day of the month and time
Hello
Using oracle 11.2.0.3
A table with a column date
sample opening time data 04/08/2014-08:30 one single column, another column start date 04/02/2014
Want to have a sql that will go through an opening time table set on the first day of the month as well as existing time
for example expect times to be
04/01/2014 08:30
Code below will give the first day of the month
What is the best way to achieve this-date data type columns.
{code}
Select trunc(start_time,'MM))
of customer_hours ch
{code}
Select
SYSDATE - trunc (sysdate) + trunc (sysdate, 'MM')
of the double
resp.
Select
start_time - trunc (start_time) + trunc (start_time, 'MM')
of the double
-
First day of the month between 08:00 and 18:30
DB version: 10.2.0.4
Due to the nature of our the first working day of each month (like today 1 MS), the DB will be very busy.
We execute a proc purge planned Windows Scheduler every 5 minutes every day.
But the first day of every month (like today 1 MS), if it's a day of the week (Monday to Friday) we do not want this proc running between 08:00 and for dinner from 18:30.
So, I thought including the logic in the procedure itself.
How can I implement this?
Edited by: user872043, Sep 1 2010 08:48Here is an example of using DBMS_SCHEDULER which should meet your needs:
Create schedules
BEGIN DBMS_SCHEDULER.CREATE_SCHEDULE ( schedule_name => 'every_5_schedule' , repeat_interval => 'FREQ=MINUTELY; BYMONTHDAY=2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31; INTERVAL=5; BYSECOND=0' , comments => 'Schedule to run every 5 minutes' ); DBMS_SCHEDULER.CREATE_SCHEDULE ( schedule_name => 'busy_hourly_schedule' , repeat_interval => 'FREQ=MINUTELY; BYMONTHDAY=1; BYHOUR=0,1,2,3,4,5,6,7,19,20,21,22,23; INTERVAL=5;' , comments => 'Schedule to run every 5 minutes except certain hours on the first of the month' ); DBMS_SCHEDULER.CREATE_SCHEDULE ( schedule_name => 'busy_6pm_schedule' , repeat_interval => 'FREQ=MINUTELY; BYMONTHDAY=1; BYHOUR=18; BYMINUTE=30,35,40,45,50,55' , comments => 'Schedule to run every 5 minutes from 6:30 - 7' ); END; /
There are three lists.
every_5_schedule - runs every 5 minutes for all the days that are not on the first day of the month
busy_hourly_schedule - runs every 5 minutes for the acceptable hours on the first day of the month
busy_6pm_schedule - retrieves the half hour from 6:30 - 7 on the first day of the month.Then, create your business:
Job creation
BEGIN DBMS_SCHEDULER.CREATE_JOB ( job_name => 'YOUR JOB' , job_type => 'PLSQL_BLOCK' , job_action =>'BEGIN YOURPROC; END;' , repeat_interval => 'EVERY_5_SCHEDULE, BUSY_HOURLY_SCHEDULE, BUSY_6PM_SCHEDULE' , enabled => TRUE , comments => 'Some comments' ); END; /
HTH!
-
Hi friends here is the querry I wrote to display every first day of the month, but there is something wrong in it... Help me...
create or replace procedure minmax is
cursor minmax_cur is
Select min (hiredate), max in emp (hiredate);
number of v_minmonths;
number of v_maxmonths;
number of v_minyears;
number of v_maxyears;
x date of publication;
date of y;
Start
Open minmax_cur;
extraction minmax_cur
x, y;
v_minmonths: = extraction (x months);
v_minyears: = extraction (year x);
While (x, y) loop
because me in 1... v_minmonths loop
If (v_minmonths < 12) then
v_minmonths: = v_minmonths + 1;
x: = x + 28.
dbms_output.put_line(v_minmonths ||) '/' || '01'. '/' ||
v_minyears);
on the other
v_minmonths: = 0;
v_minyears: = v_minyears + 1;
x: = x + 28.
end if;
end loop;
end loop;
minMax end;
and the results are
01/01/1981
01/02/1981
01/03/1981
..................
.........---
01/04/1987
01/05/1987
01/06/1987
01/07/1987
01/08/1987
01/09/1987
01/10/1987
01/11/1987 the problem is max (hiredate) is 5/23/1987...it must show up to 01/05/1987...
I get a few more months...
-
find the first day of the month
Hello...
can u pls let me know how to find the first day of the month, if the number of months (for ex - OCT-10) is passed as input
Kind regardsI'm not sure that there is a function called FIRST_DAY().
SQL> SELECT first_day (SYSDATE) 2 FROM DUAL; SELECT first_day (SYSDATE) * ERROR at line 1: ORA-00904: "FIRST_DAY": invalid identifier SQL> SELECT TRUNC (SYSDATE, 'month') 2 FROM DUAL; TRUNC(SYS --------- 01-DEC-08 SQL>
I hope this helps.
Kind regards
Joice -
Function to retrieve the first day of the month.
Select (sysdate, 'IW') of double
I know it takes the date of Monday. Is there a function like above that has the date of return to the first Monday of the month?
Thanks in advance.Hello
NEXT_DAY is very convenient, but it is dependent on the NLS_DATE_LANGUAGE, and you cannot pass an argument to override that.
TRUNC (dt, 'IW') is not in the NLS settings, then you may prefer this:TRUNC ( 6 + TRUNC (SYSDATE, 'MONTH') , 'IW' ) AS first_monday
1st Monday of the month is fixed to the Monday or before the 7th of the month.
-
Hello
How can I get the (day number of the) last day of a given month and year?
So, if
year 2015 = and month = 1, the output should be 31
year = 2012 and month = 2 while production is expected to be 29
year 2013 = and month = 2 while production is expected to be 28
etc.
Y at - it no OBIEE to achieve? If not, then a command SQL Oracle is very good too (I prefer OBIEE however)
Thanks in advance,
Erik
You start from the first day of the month, you add 1 month [TIMESTAMPADD (SQL_TSI_MONTH, 1, 'your date')], you must subtract 1 day [TIMESTAMPADD (SQL_TSI_DAY,-1, 'your date')] and use the DAYOFMONTH function to get the number of the last day of the month [DAYOFMONTH ('your ' date')].
All these calls nesting together and you're there.
-
Last day of the month with the last minute of the day
Hello
I wonder about how to get the last day of the month with the last minute of this day(23:59). We can use the last_day function (DATE) to get the last date, but reminds me of the time of day when the function has been executed. But I want to have the last minute with my last date of the current month.
Please inform.
Thank you
HPHello
Ora_bie wrote:
Hello
I wonder about how to get the last day of the month with the last minute of this day(23:59). We can use the last_day function (DATE) to get the last date, but reminds me of the time of day when the function has been executed. But I want to have the last minute with my last date of the current month.In fact, it returns at the same time as the argument you pass; But whatever it is, is not what you want.
This will return the last day of the month that contains the DATE 23:59 (or 23:59) dt:
SELECT ADD_MONTHS ( TRUNC (dt, 'MONTH') , 1 ) - (1 / (24 * 60)) FROM dual ;
TRUNC (dt, 'MONTH') is 00:00 on the first day of the month that contains dt.
ADD_MONTHS (TRUNC (dt, 'MONTH'), 1) is from 00:00 the first day of the month following the one containing dt.
ADD_MONTHS (TRUNC (dt, 'MONTH'), 1)-(1 / (24 * 60)) is a minute earlier.
(Since there are 24 hours, each with 60 minutes, every day, 1 / (24 * 60) days is identical to a minute.)Another (less clear, in my opinion) way to get the same results is:
TRUNC (LAST_DAY (dt)) + (1439/1440) -- 1440 minutes = 1 day
-
Hello people:
I have currently a query that picks up all the weeks between a date range where my week starts on Thursday and ends on Wednesday. The following query works fine except that I need the week of beginning and end, from beginning and end Dates of months and the beginning and the Dates of end of the values of the settings, I'm passing. In this case, I chose January 1, 2013 to 31 December 2013.
Any help or pointers would be great!
Thank you!
Problem: I am picking up days of December 2012 as the first week began on December 27, 2012. In addition, in December, I'm pretty much lost last week as well (26 December - 31 December).
The request in hand:
SELECT first_thursday + (7 * (LEVEL - 1)) AS week_start_date, first_thursday + (7 * LEVEL) - 1 AS week_end_date FROM ( SELECT TRUNC(p_from_date + 4, 'IW') - 4 AS first_thursday, -- Week should start the pre ceeding THURSDAY based on the Start Date TRUNC( p_to_date + 4, 'IW') - 5 AS last_wednesday FROM ( SELECT to_date('01-JAN-2013') AS p_from_date, NVL(to_date('31-DEC-2013'), SYSDATE) AS p_to_date FROM dual ) parms ) end_points CONNECT BY LEVEL <= ( last_wednesday + 1 - first_thursday)/7;
Currently, this is the result I get (I'm only including the months of January and December here).
Week_Start_Date Week_End_Date 27-DEC-12 02-JAN-13 03-JAN-13 09-JAN-13 10-JAN-13 16-JAN-13 17-JAN-13 23-JAN-13 24-JAN-13 30-JAN-13 31-JAN-13 06-FEB-13
December:
28-NOV-13 04-DEC-13 05-DEC-13 11-DEC-13 12-DEC-13 18-DEC-13 19-DEC-13 25-DEC-13
What I would really like is based on start and end Dates, as well as the first and the last day of the month is similarly try nicely. I have provided and then gently break at the end of the month:
January:
01-JAN-13 02-JAN-13 03-JAN-13 09-JAN-13 10-JAN-13 16-JAN-13 17-JAN-13 23-JAN-13 24-JAN-13 30-JAN-13 31-JAN-13 31-JAN-13
February:
01-FEB-13 06-FEB-13 07-FEB-13 13-FEB-13 14-FEB-13 20-FEB-13 21-FEB-13 27-FEB-13 28-FEB-13 28-FEB-13
November:
31-OCT-13 06-NOV-13 07-NOV-13 13-NOV-13 14-NOV-13 20-NOV-13 21-NOV-13 27-NOV-13 28-NOV-13 04-DEC-13
December:
01-DEC-13 04-DEC-13 05-DEC-13 11-DEC-13 12-DEC-13 18-DEC-13 19-DEC-13 25-DEC-13 26-DEC-13 31-DEC-13
Hello
Roxyrollers wrote:
Hello people:
I have currently a query that picks up all the weeks between a date range where my week starts on Thursday and ends on Wednesday. The following query works fine except that I need the week of beginning and end, from beginning and end Dates of months and the beginning and the Dates of end of the values of the settings, I'm passing. In this case, I chose January 1, 2013 to 31 December 2013.
Any help or pointers would be great!
Thank you!
Problem: I am picking up days of December 2012 as the first week began on December 27, 2012. In addition, in December, I'm pretty much lost last week as well (26 December - 31 December).
The request in hand:
- First_thursday SELECT + (7 * (LEVEL - 1)) AS week_start_date,
- first_thursday + (7 * LEVEL)-1 AS week_end_date
- Of
- (
- SELECT TRUNC (p_from_date + 4, 'IW') - 4 AS first_thursday,-week should start to perform the pre-mounted THURSDAY based on the Start Date
- TRUNC (p_to_date + 4, 'IW') - 5 AS last_wednesday
- Of
- (
- SELECT to_date('01-JAN-2013') AS p_from_date,
- NVL (to_date('31-Dec-2013'), SYSDATE) AS p_to_date
- OF the double
- ) parms
- ) end_points
- CONNECT BY LEVEL<= (="" last_wednesday="" +="" 1="" -="">=>
Currently, this is the result I get (I'm only including the months of January and December here).
- Week_Start_Date Week_End_Date
- DECEMBER 27, 12 2 JANUARY 13
- JANUARY 3, 13 JANUARY 9, 13
- 10 JANUARY 13 JANUARY 16, 13
- 17 JANUARY 13 23 JANUARY 13
- 24 JANUARY 13 30 JANUARY 13
- 31 JANUARY 13 FEBRUARY 6, 13
December:
- NOVEMBER 28, 13 4 DECEMBER 13
- 5 DECEMBER 13 DECEMBER 11, 13
- 12 DECEMBER 13 18 DECEMBER 13
- 19 DECEMBER 13 DECEMBER 25, 13
What I would really like is based on start and end Dates, as well as the first and the last day of the month is similarly try nicely. I have provided and then gently break at the end of the month:
January:
- JANUARY 1, 13 2 JANUARY 13
- JANUARY 3, 13 JANUARY 9, 13
- 10 JANUARY 13 JANUARY 16, 13
- 17 JANUARY 13 23 JANUARY 13
- 24 JANUARY 13 30 JANUARY 13
- 31 JANUARY 13 JANUARY 31, 13
February:
- 1ST FEBRUARY 13 FEBRUARY 6, 13
- 7 FEBRUARY 13 FEBRUARY 13, 13
- 14 FEBRUARY 13 FEBRUARY 20, 13
- 21 FEBRUARY 13 FEBRUARY 27, 13
- 28 FEBRUARY 13 FEBRUARY 28, 13
November:
- 31 OCTOBER 13 NOVEMBER 6, 13
- 7 NOVEMBER 13 NOVEMBER 13, 13
- 14 NOVEMBER 13 NOVEMBER 20, 13
- 21 NOVEMBER 13 NOVEMBER 27, 13
- NOVEMBER 28, 13 4 DECEMBER 13
December:
- 1ST DECEMBER 13 DECEMBER 4, 13
- 5 DECEMBER 13 DECEMBER 11, 13
- 12 DECEMBER 13 18 DECEMBER 13
- 19 DECEMBER 13 DECEMBER 25, 13
- 26 DECEMBER 13 DECEMBER 31, 13
Why the "weeks" in November, have all 7 days, while the "weeks" in the first or the last week in the other month usually have less? (For example, February 28 is a 'week' alone.)
The following works for the other months:
WITH all_days AS
(
SELECT DATE "2013-01-01' + LEVEL - AS a_date 1
OF the double
CONNECT BY LEVEL<=>=>
)
SELECT DISTINCT
More GRAND (TRUNC (a_date + 4, 'IW') - 4)
, TRUNC (a_date, 'MONTH')
) AS week_begin
, The LEAST (TRUNC (a_date + 4, 'IW') + 2
TRUNC (LAST_DAY (a_date))
), Week_end
Of all_days
ORDER BY week_begin
;
Output:
WEEK_BEGIN WEEK_END
----------- -----------
January 1, 2013 January 2, 2013
January 3, 2013 January 9, 2013
January 10, 2013 January 16, 2013
January 17, 2013 January 23, 2013
January 24, 2013 January 30, 2013
January 31, 2013 January 31, 2013
February 1, 2013 February 6, 2013
February 7, 2013 February 13, 2013
February 14, 2013 February 20, 2013
February 21, 2013 February 27, 2013
February 28, 2013 February 28, 2013
...
November 1, 2013 November 6, 2013
November 7, 2013 November 13, 2013
November 14, 2013 November 20, 2013
November 21, 2013 November 27, 2013
November 28, 2013 November 30, 2013
December 1, 2013 December 4, 2013
December 5, 2013 December 11, 2013
December 12, 2013 December 18, 2013
December 19, 2013 December 25, 2013
26 December 2013 31 December 2013
-
Select the first 20 days of the month for a given date
Hi gurus,
Please let me know to select the first 20 dates for a date supplied by using a parameter.
For ex -.
Suppose I provided a date by using a parameter - January 13, 2012
The query should return me - 01-Jan-2012, January 2, 2012... January 20, 2012
or if I get home on 23 March 2012
The query should return me - 01-Mar-2012, March 2, 2012... 20 March 2012
Thanks in advance.Hello
Here's one way:
VARIABLE target_date VARCHAR2 (11) EXEC :target_date := '13-Jan-2012'; SELECT TO_DATE ( SUBSTR (:target_date, 4) , 'Mon-YYYY' ) + LEVEL - 1 AS a_date FROM dual CONNECT BY LEVEL <= 20 ;
Note that this does not take account the part of: target_date that represents the day of the month. When you use TO_DATE without giving a date of the month, it defaults to the 1st of the month.
-
Get the first and the last day of the month...
Hi friends,
I'm trying to get the first and last day of a month and wants to implement that in the following code:
SELECT COALESCE (Date_A, Date_B, Date_C)
OF the double
Here Date A and B are in Format DD MM YYYY (March 14, 2008)
and Date like MM YYYY (March 2008)
How can I get the Date_C as of March 1, 2008, OR March 31, 2008 if Date A and B are NULL?
Thank you!
Published by: user11095386 on April 23, 2009 10:45Hello
In my previous message, I thought that you were starting with strings like ' 03 12 2009"and you want to display in the form of" 12 March 2009'.» If what you have is just the opposite, then simply reverse strings format in my first message. Add a comma, if you want, in the format string.
I think that's 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 so, by default the day the 1st of the month, so that's all you need to do to convert the VARCHAR2 'March 2009' at the DATE of March 1, 2009.
If you would like the last day of the month, not the first, when Date_C is selected, 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' ) )
-
Change of blackBerry Smartphones first day of the calendar
I want to change the first day of the week. I looked around in the menus of the storm, but I don't the have not found. Where can I change the first day of the week in the monthly calendar view? Thank you
Open the calendar, press the menu key, search 'options' and select it, choose 'General Options '. You should be able to understand the rest .
Maybe you are looking for
-
Is it possible to update the toshiba recovery cdwith Windows XP SP 2 and other patches or find newupdated toshiba recovery CD?
-
Comcast of WMC block registration function
I have WMC 2005 for XP. Comcast in my area of MN has decided to make all the digital channels, (same basic channels) I can always get the channels to change, but I have to do manually and with two remotes. My WMC will record is no longer present beca
-
I requested a copy of the document, but the printer does not respond.
HPofficejet5610all-in-one, I placed a doc in demand, but the printer does not respond. My icon shows document it and printer status says ready. I even changed the ports, but nothing happens. When I checked on what Control Panel first shows for printe
-
Migration of VMware player for ESXi strike SCSi problem
HelloI'm just a newbee with VMware.First, I installed Centos 6.2 on VMware Player.Then I download the Virtual Machine on Esxi5 U1 directory using the VMware client. (not the converter)Then I tried to use the VHD with creating new virtual machine on E
-
RAM Preview needs 2 or more error management
HelloI just encountered this error for the first time since I started using AE about 6 years ago.I use a PC (windows 7 pro), i5 2.90 GHz 64-bit OS, 16 GB of RAM and 1 GB graphics card, dedicated 1 TB HDD for the Cache. Creative cloud subscription.I h