Date between 2 dates


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Date between 2 dates
# 1  
Old 05-11-2015
Date between 2 dates

Hi All,
Can you help me in finding the business dates (Mon-Fri) between two date ranges.. (forget abt holidays in weekdays)

searched and tried a lot but cant figure this. ISs there any special function availble in unix for this
# 2  
Old 05-11-2015
What version of UNIX do you have: uname -a will tell you.

I am guessing: you are coding in shell - which one?

These answers will help us hlp you.
# 3  
Old 05-11-2015
A question i really like:
What have you tried so far by yourself?
# 4  
Old 05-11-2015
Are you really talking of two date ranges or one range between two limits?
# 5  
Old 05-11-2015
yes, im using Linux 2.6.32-431.29.2.el6.x86_64
trying to get this in bash script.

tried so many commands,
Code:
echo $(($(($(date -d "20150511" "+%s") - $(date -d "20150411" "+%s"))) / 86400))

this gives only the day difference

Code:
cal | cut -c 4-17

this give only the dates between mon-friday.

I want to get all the business dates between some limit. so i will pass my start date and end date in my script.
And want to get all the BUSINESS DATES (not days) within the specified range so i need to perform some operation on these dates.

Last edited by rbatte1; 05-11-2015 at 12:42 PM.. Reason: Added ICODE tags for version output and tightened CODE tags
# 6  
Old 05-11-2015
With datfile containing
Code:
20150411
20150511

, try
Code:
date -fdatfil +"%s %u" | { read T2 D2; read T1 D1; echo $(((T1 - T2) * 5 / (86400 * 7) + ((D1 - D2)>0?2:0) )) ; }
21

This is a coarse approxiation and NOT thoroughly tested but for just a handful of ranges, and it has difficulties when the range limits fall into weekends, but it gets pretty close and puts you into a position to optimize.

Last edited by RudiC; 05-11-2015 at 12:14 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Splitting week start date and end date based on custom period start dates

Below are my custom period start and end dates based on a calender, these dates are placed in a file, for each period i need to split into three weeks for each period row, example is given below. Could you please help out to achieve solution through shell script.. File content: ... (2 Replies)
Discussion started by: nani2019
2 Replies

2. Shell Programming and Scripting

ksh compare dates INSIDE a file (ie date A is > date B)

In KSH, I am pasting 2 almost identical files together and each one has a date and time on each line. I need to determine if the first instance of the date/time is greater than the 2nd instance of the date/time. If the first instance is greater, I just need to echo that line. I thought I would... (4 Replies)
Discussion started by: right_coaster
4 Replies

3. Shell Programming and Scripting

Need to capture dates between start date and end date Using perl.

Hi All, Want to get all dates and Julian week number for that date between the start date and end date. How can I achive this using perl? (To achive above functionality, I was connecting to the database from DB server. Need to execute the same script in application server, since databse... (6 Replies)
Discussion started by: Nagaraja Akkiva
6 Replies

4. Shell Programming and Scripting

Need to capture all dates between start date and End date.

Hi All, I enter Start date and end date as parameters. I need to capture dates between start date and end date. Please let me know if you have any idea the same. Thanks in advance. Nagaraja Akkivalli. (5 Replies)
Discussion started by: Nagaraja Akkiva
5 Replies

5. Shell Programming and Scripting

Using 'date' to list a range of dates

Hi guys, I have been trying to create a list of dates from a certain range, ie. range from 01011950 to 31122000 But when my below code reaches certain dates, it comes up with a; 'date: invalid date 'yyyy-mm-dd -d 1day' Sofar I have come up with the following, slow and ugly; ... (4 Replies)
Discussion started by: TAPE
4 Replies

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

7. Shell Programming and Scripting

Display the last five dates from the given date

Hi all, In Oracle we have got sysdate -1 to find the previous date. Is there any similar way to display date in unix shell scripting? Kindly help me to display the last five dates from the given date Thanks, Geetha (11 Replies)
Discussion started by: iamgeethuj
11 Replies

8. UNIX for Dummies Questions & Answers

Display dates within a given date range

Hi All, I have a requirement to display all the dates within the provided (through user input) date range. For eg: If I enter 28012009 (as From date in the format 'DDMMYYYY') and 02022009(as To date in the format 'DDMMYYYY'), the output should be all dates occuring between the from and to... (11 Replies)
Discussion started by: sunpraveen
11 Replies

9. UNIX for Dummies Questions & Answers

using 'date' to get previous days' dates

I am familiar with using the 'date' command to get the current date but I have a situation where I need to get the previous day's date as well as the date two days prior. Theoretically I could use 'expr' to compute these values but I need it to work in instances where the previous month's dates... (2 Replies)
Discussion started by: slant-40
2 Replies

10. UNIX for Dummies Questions & Answers

While we are on the subject of dates. Another date question

This goes deeper into the date thing. I want to be able to check the date and time stamp in or on a file to see what the time span is. We have a job that runs several times an hour - kicked off through cron based on a trigger file. We want to keep track of each run and check the time between... (14 Replies)
Discussion started by: MizzGail
14 Replies
Login or Register to Ask a Question