Need difference between days


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need difference between days
# 1  
Old 12-01-2015
Hammer & Screwdriver Need difference between days

Hi,

I am not comfortable with dates and I fail to crack this.

I have two strings

Code:
Date1="Apr 22 23:59:59 2016 GMT"
Date2="Dec  1 15:08:40 UTC 2015"

I need to find the difference in days between the two dates which in this example is approx 140 days.

Is there an easy way to get the difference in days ?

Last edited by Scrutinizer; 12-01-2015 at 12:16 PM.. Reason: code tags
# 2  
Old 12-01-2015
This depends on your system. What be the OS, shell, date versions?
# 3  
Old 12-01-2015
Quote:
Originally Posted by RudiC
This depends on your system. What be the OS, shell, date versions?
I'm on Linux x86_64 GNU/Linux. I can use Bash or C shell.
Code:
uname -r
2.6.32-431.5.1....

rpm -qa | grep date
python-dateutil-1.4.1-6.el6.noarch


Last edited by mohtashims; 12-01-2015 at 12:35 PM..
# 4  
Old 12-01-2015
Try this bashism:
Code:
echo $((($(date -d"Apr 22 23:59:59 2016 GMT" +%s) - $(date -d"Dec 1 15:08:40 UTC 2015" +%s)) / 86400))
143

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to find a file that's modified more than 2 days ago but less than 5 days ago?

How to find a file that's modified more than 2 days ago but was modified less than 5 days ago by use of any Linux utility ? (4 Replies)
Discussion started by: abdulbadii
4 Replies

2. Shell Programming and Scripting

Trouble calculating difference in number of days

Hi all, I have a requirement to calculate the difference of number of days of time stamp of a file and system date and if the difference is greater than 15 days it should prompt as previous month file otherwise current month file. Below is the code i used and it is working fine till now. (You... (2 Replies)
Discussion started by: Ravindra Swan
2 Replies

3. Shell Programming and Scripting

Working out days of the week and processing file in 3 working days

Hi guys i need advice on the approach to this one...... I have a file say called Thisfile.20130524.txt i need to work out from the date 20130524 what day of the week that was and then process the file in 3 working days. (so not counting saturday or sunday....(will not worry about bank... (2 Replies)
Discussion started by: twinion
2 Replies

4. Shell Programming and Scripting

Difference in dates in days (ksh shell)

Hi Guys, Need a small help, how do i get the difference between two dates (in days) in KSH shell My date is in mm/dd/YYYY format, Is there a function to get time stamp from the respective date and time ( mm/dd/yyyy HH:MM:SS) (1 Reply)
Discussion started by: selvankj
1 Replies

5. Programming

what is the main difference between difference between using nonatomic lseek and O_APPEND

I think both write at the end of the file ...... but is there a sharp difference between those 2 instruction ..... thank you this is my 3rd question today forgive me :D (1 Reply)
Discussion started by: fwrlfo
1 Replies

6. Shell Programming and Scripting

days difference perl

Hi I have the following issue. the headeer in the file contains as follows IMAHDR tsmdsl01 EMBS_DAT 20120911 20120911 233656S000000000000000 001 So the fifth field in the header is a string that represents the file arrival date.(20120911) yyyyMMDD I just need to compare... (1 Reply)
Discussion started by: ptappeta
1 Replies

7. Shell Programming and Scripting

date for two days or 3 days ago

i need a script that can tell me the date 2 days ago or 3 days ago. please help (7 Replies)
Discussion started by: tomjones
7 Replies

8. Shell Programming and Scripting

Days difference between two dates

Hello, I would like to find out the number of days between two dates of the format yyyy-mm-dd. Any help on this is highly appreciated. Thanks. (6 Replies)
Discussion started by: Data469
6 Replies

9. Shell Programming and Scripting

ls latest 4 days or specify days of files in the directory

Hi, I would like to list latest 2 days, 3 days or 4 days,etc of files in the directory... how? is it using ls? (3 Replies)
Discussion started by: happyv
3 Replies

10. Shell Programming and Scripting

Difference between two dates in no of days ???

Hi All How to get the difference between two dates in no of days ??? My date format is like this YYYY/MM/DD. I have to get the no of days between two dates in the given format. I tried to search the forum but nothing came up similar to my requitement. Your help will be appreciated. ... (1 Reply)
Discussion started by: csaha
1 Replies
Login or Register to Ask a Question