Sponsored Content
Top Forums Shell Programming and Scripting Shell Script to Loop through Quarter dates Post 303002405 by krux_rap on Wednesday 23rd of August 2017 02:29:57 PM
Old 08-23-2017
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.
Code:
1 20170701 20170930
2 20171001 20171231
3 20180101 20180331
4 20180401 20180630

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 ----------

Code:
today=$(date +%Y%m%d)
while read quarter start end
do
if [ $start -ge $today ]
then
   exit
fi
if [ $today -gt $end ]
then
  let new_end=$today-$(date +%d)+1        #first day of month
  let new_end=$(date +%Y%m%d --date="$new_end yesterday")   #last day of previous month
fi
if [ $new_end -le $start ]
then
   exit  
else 
   end=$new_end
fi
do sql with $quarter $start $end
done <quarter_file

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to compare the dates in shell script

Hi How to compare created or modified date of two files help needed thanks Vajiramani :) (9 Replies)
Discussion started by: vaji
9 Replies

2. Shell Programming and Scripting

Generate quarter dates with begin date and end date

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)
Discussion started by: sol_nov
9 Replies

3. Shell Programming and Scripting

Difference of 2 dates in shell script

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)
Discussion started by: IND123
6 Replies

4. UNIX for Dummies Questions & Answers

Find Quarter Start and End Dates

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)
Discussion started by: sandeep_1105
1 Replies

5. Shell Programming and Scripting

append dates going forward from today to certain line in shell script

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)
Discussion started by: Slyesco
2 Replies

6. Shell Programming and Scripting

Shell script to calculate difference between 2 dates

shell script to calculate difference between 2 dates (3 Replies)
Discussion started by: gredpurushottam
3 Replies

7. Shell Programming and Scripting

Need Help:Shell Script for Solaris to change the dates in a file by one week

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)
Discussion started by: sriramanaramoju
3 Replies

8. Shell Programming and Scripting

Shell script to work on dates

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)
Discussion started by: kumar85shiv
4 Replies

9. Shell Programming and Scripting

Comparing dates in shell script

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)
Discussion started by: Girish19
1 Replies

10. Linux

How to calculate the quarter end date according to the current date in shell script?

Hi, My question is how to calculate the quarter end date according to the current date in shell script? (2 Replies)
Discussion started by: Divya_1234
2 Replies
Time::CTime(3)						User Contributed Perl Documentation					    Time::CTime(3)

NAME
Time::CTime -- format times ala POSIX asctime SYNOPSIS
use Time::CTime print ctime(time); print asctime(localtime(time)); print strftime(template, localtime(time)); strftime conversions %% PERCENT %a day of the week abbr %A day of the week %b month abbr %B month %c ctime format: Sat Nov 19 21:05:57 1994 %d DD %D MM/DD/YY %e numeric day of the month %f floating point seconds (milliseconds): .314 %F floating point seconds (microseconds): .314159 %h month abbr %H hour, 24 hour clock, leading 0's) %I hour, 12 hour clock, leading 0's) %j day of the year %k hour %l hour, 12 hour clock %m month number, starting with 1 %M minute, leading 0's %n NEWLINE %o ornate day of month -- "1st", "2nd", "25th", etc. %p AM or PM %r time format: 09:05:57 PM %R time format: 21:05 %S seconds, leading 0's %t TAB %T time format: 21:05:57 %U week number, Sunday as first day of week %w day of the week, numerically, Sunday == 0 %W week number, Monday as first day of week %x date format: 11/19/94 %X time format: 21:05:57 %y year (2 digits) %Y year (4 digits) %Z timezone in ascii. eg: PST DESCRIPTION
This module provides routines to format dates. They correspond to the libc routines. &strftime() supports a pretty good set of coversions -- more than most C libraries. strftime supports a pretty good set of conversions. The POSIX module has very similar functionality. You should consider using it instead if you do not have allergic reactions to system libraries. GENESIS
Written by David Muir Sharnoff <muir@idiom.com>. The starting point for this package was a posting by Paul Foley <paul@ascent.com> LICENSE
Copyright (C) 1996-1999 David Muir Sharnoff. License hereby granted for anyone to use, modify or redistribute this module at their own risk. Please feed useful changes back to muir@idiom.com. perl v5.12.1 2004-02-08 Time::CTime(3)
All times are GMT -4. The time now is 11:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy