Convert date into days using shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert date into days using shell script
# 1  
Old 05-16-2014
Convert date into days using shell script

Hi,

I have date format in an excel sheet as 07/03/2014 11:21. I need to check this date with current date and need to find whether it is more than 30 days or not.
I know how to current date into days, but someone please help me to change the date in the excel sheet to days, so that i can check with simple expr function.

Regards,
Arasu
# 2  
Old 05-16-2014
With GNU date, you can do something like this, in sh or bash:
Code:
#!/bin/sh

# Past date in seconds since Epoch
past=$(date +%s --date "12/02/2013 11:21")

# Now in seconds since Epoch
now=$(date +%s)

# Interval in seconds -- 30 days in this case
interval=$((30*86400)) #86400 seconds per day

if [ "$((now-past))" -gt "$interval" ]; then x='more'; else x='less'; fi

printf '%s\n' "Past date is $x than 30 days"

exit 0

This User Gave Thanks to tukuyomi For This Post:
# 3  
Old 05-16-2014
Quote:
Originally Posted by Arasu123
Hi,

I have date format in an excel sheet as 07/03/2014 11:21. I need to check this date with current date and need to find whether it is more than 30 days or not.
I know how to current date into days, but someone please help me to change the date in the excel sheet to days, so that i can check with simple expr function.

Regards,
Arasu
If you have that in Excel already, why not just do it in Excel? Wouldn't that be easier ?

Use this formula:

Code:
=B2+30<TODAY()

where B2 is the cell with your date of 07/03/2014 11:21

That'll return TRUE if it's older than 30 days, FALSE if not.

By the way, is that March 7? or Jun 3 ?
:P

If you want it to return a numeric (maybe easier to use in Unix later):
Code:
=if(B2+30<TODAY(), 1, 0)

1 = old
0 = not old
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert string to date and add 20 days

Hi, I have a requirement where I am getting date in string format (20161130). I need to add 20 days(not no. 20) to the above string. The o/p should 20161220. In case of 20170228, it should show 20170320. Could you please help me with the command to achieve this. Note: I am using AIX 7.1... (5 Replies)
Discussion started by: satyaatcgi
5 Replies

2. UNIX for Dummies Questions & Answers

Unable to convert date into no. using date -d +%s syntax in ksh shell

hi friends, I m trying to write a script which compares to dates. for this i am converting dates into no using synatx as below v2=`date | awk '{print $2,$3,$4}'` v3=`date +%s -d "$v2"` this syntax is working in bash shell ,but fails in ksh shell. please suggest on this. (12 Replies)
Discussion started by: Jcpratap
12 Replies

3. Shell Programming and Scripting

Substracting days from current date(K shell script)

Hi, I want to subtract 'n' days from the current timestamp in a k shell script. Is there any inbuilt function to do it or any workaround solution to get the date. And I want the output to be in YYYY:MM:DD HH:MM:SS format. Please help. Thanks in advance. (4 Replies)
Discussion started by: Suryaaravindh
4 Replies

4. Shell Programming and Scripting

How to Get 60 days Old date from current date in KSH script

Hi i am writing a cron job. so for it i need the 60 days old date form current date in variable. Like today date is 27 jan 2011 then output value will be stote in variable in formet Nov 27. i am using EST date, and tried lot of solution and see lot of post but it did not helpful for me. so... (3 Replies)
Discussion started by: Himanshu_soni
3 Replies

5. Windows & DOS: Issues & Discussions

Adding or subtracting days from current date in batch script

Hi, I'm writing an batch file to create report In the batch file iam passing two arguments:startdate and finishdate Ex: startdate=07-sep-2009 finishdate=07-sep-2011 I need to have script that takes command line argument as input and gives me out currentdate last year and current date... (2 Replies)
Discussion started by: anand1773
2 Replies

6. AIX

Convert string to date in script

Hi, How can I convert a string "Jul 10 09" to date in aix? the output can be like 20090710. Thanks. (4 Replies)
Discussion started by: Gbyte
4 Replies

7. Shell Programming and Scripting

Calculate 30/31 days from today date script

Hi Guys, I was working some time ago n was in need to calculate date 30/31 days from today including Feb (Leap yr stuff). Today date is variable depending on day of execution of script. I tried searching but was not able to get exactly what I needed....So at that I time I implemented by my own... (3 Replies)
Discussion started by: coolgoose85
3 Replies

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

9. UNIX for Dummies Questions & Answers

script to convert absolute date

Hi , I have a csv file and column 1 is date in the cursed YYYY-M-D format. Is there any way to convert 1st column to an absolute date say using 1977-1-1 as day 1? Thanks a lot. (2 Replies)
Discussion started by: onthetopo
2 Replies

10. AIX

convert date in lilian format for shell (AIX)

hello ! can so help me ? i'm writting a shell srcipt ( UNIX AIX) and I'd like to convert a date as 20041108 in lilian format. thanks so much (2 Replies)
Discussion started by: chocolate
2 Replies
Login or Register to Ask a Question