Trying to automate a Postgres query using Shell script
Every month 1st week has to run a Monthly Queries to generate delimited files.
July 1st start of fiscal yr which has 4 Quarters until next June 30th
Example
If I'm running on Sept 5th it has to generate one file(Becuase it falls under first Quarter), dates should be between 2017-07-01 and 2017-08-31 to Postgres SQL as Input.
July - Sept (1 file)
Oct - Dec (2 files which should generate above file too)
Jan - Mar (3 files)
April - Jun (4 files)
Another Example
If I ran the script on Nov 5th, then it has to get me 2 sets of files
One from July 1st to Sept 30th
2nd file from Oct 1st to Oct 31st
Last edited by rbatte1; 08-22-2017 at 06:52 AM..
Reason: Added bullet lists
I would be inclined to create a data file rather than a lot of arithmetic.
Then you read this file for the number of quarters you are reporting. This is also way easier to modify if the company gets sold and changes its year end.
---------- Post updated 08-22-17 at 10:19 AM ---------- Previous update was 08-21-17 at 10:51 PM ----------
If I'm running on Sept 5th it has to generate one file(Becuase it falls under first Quarter), dates should be between 2017-07-01 and 2017-08-31 to Postgres SQL as Input.
July - Sept (1 file)
Oct - Dec (2 files which should generate above file too)
Jan - Mar (3 files)
April - Jun (4 files)
Another Example
If I ran the script on Nov 5th, then it has to get me 2 sets of files
One from July 1st to Sept 30th
2nd file from Oct 1st to Oct 31st
...
...
What should be in the files if the end of previous month is also the end of previous quarter?
For example, if the process is run on 4-Oct-2017, then:
1) "File 1" has dates of Quarter 1 i.e. 01-Jul-2017 to 30-Sep-2017
2) What dates does "File 2" have?
A few similar cases are below:
Process Date: 05-Jan-2018
File 1 : Dates of Quarter 1 i.e. 01-Jul-2017 to 30-Sep-2017
File 2 : Dates of Quarter 2 i.e. 01-Oct-2017 to 31-Dec-2017
File 3 : What dates does this have?
Process Date: 05-Apr-2018
File 1 : Dates of Quarter 1 i.e. 01-Jul-2017 to 30-Sep-2017
File 2 : Dates of Quarter 2 i.e. 01-Oct-2017 to 31-Dec-2017
File 3 : Dates of Quarter 3 i.e. 01-Jan-2018 to 31-Mar-2018
File 4 : What dates does this have?
Also, what dates should be in the file(s) if the process is run in July of any year?
For example, if the process is run on 4-Oct-2017, then:
1) "File 1" has dates of Quarter 1 i.e. 01-Jul-2017 to 30-Sep-2017
2) What dates does "File 2" have? We will be generating only 1 quarter file.
A few similar cases are below:
Process Date: 05-Jan-2018
File 1 : Dates of Quarter 1 i.e. 01-Jul-2017 to 30-Sep-2017
File 2 : Dates of Quarter 2 i.e. 01-Oct-2017 to 31-Dec-2017
File 3 : What dates does this have? We will be generating only 2 quarter files. NO Jan Data
Process Date: 05-Apr-2018
File 1 : Dates of Quarter 1 i.e. 01-Jul-2017 to 30-Sep-2017
File 2 : Dates of Quarter 2 i.e. 01-Oct-2017 to 31-Dec-2017
File 3 : Dates of Quarter 3 i.e. 01-Jan-2018 to 31-Mar-2018
File 4 : What dates does this have? 3 quarters only
Also, what dates should be in the file(s) if the process is run in July of any year? Generate All 4 quarters files. Because data is not complete yet in July. For that reason, we don't generate data for the month which we are running the script
But script will be running every month 1st week. So most of the time the previous month may not be the end of Quarter. So we have to consider following example also
For example, if the process is run on 4-Sept-2017, then:
Only One file has dates of Quarter 1 i.e. 01-Jul-2017 to 31-Aug-201
Let me know if anything is unclear and thanks for the follow-up questions
---------- Post updated at 02:29 PM ---------- Previous update was at 02:28 PM ----------
Thanks, JGT. the script is not working but i will use that as the base to cover all scenarios.
Quote:
Originally Posted by jgt
I would be inclined to create a data file rather than a lot of arithmetic.
Then you read this file for the number of quarters you are reporting. This is also way easier to modify if the company gets sold and changes its year end.
---------- Post updated 08-22-17 at 10:19 AM ---------- Previous update was 08-21-17 at 10:51 PM ----------
I noticed a slight error in my original script.
Also if you need to re-run an old report, just force a value for 'today'.
I would presume that if you run the report in July, you are expecting 4 quarterly reports for the previous fiscal year.
Hi All,
I have a date variable say dt="2014-01-06 07:18:38"
Now i need to use this variable to search a log and get the entries which occured after that time. (1 Reply)
Hi Sir/Madam
I have a file data.txt like below
file_name date_of_creation
x 2/10/2012
y 8/11/2010
z 11/3/2013
a 2/10/2013
b 3/10/2013
c ... (4 Replies)
I have to increase the date by one week in an input when script is executed in solaris. I was able to acheive this using ksh script that is working in Linux enivironment, when i execute the same script in Solaris i am getting below error:
/var/tmp\n\r-> ./script.ksh
date: illegal option -- d... (3 Replies)
Hi there,
I have a requirement to append dates going forward to a certain line in a file.
I'm not sure of how to go about this. Any help will be greatly appreciated.
Thanks
Slyesco:wall: (2 Replies)
Dear Members,
Depending on the current date i should find out the start and end dates of the quarter.
ex: Today date is 14-Nov-2011 then Quarter start date should be Oct 1 2011 and Quarter End date should be Dec 31 2011.
How can i do this?
Thanks
Sandeep (1 Reply)
Hi.,
After retrieving values from DB I have two datestamps in format:
12/01/2010:05:40:00 AM and 12/01/2010:06:00:00 PM.
general time format: MM/DD/YYYY:HH:MM:SS AM or PM
Any quick solution to get the difference of two in the format : 1 day(s) 12:20:00
Thanks., (6 Replies)
Hi All,
I am trying to generate quarter dates with user giving input as begin date and end date. Example: Input by user:
begin_date = "2009-01-01"
end_date = 2010-04-30"
required output:
2009-01-01 2009-03-31 09Q01
2009-04-01 2009-06-30 09Q02
.
.
till
2010-01-01 2010-03-31 10Q01
... (9 Replies)