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

With GNU date, you can do something like this, in sh or bash:

#!/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
1 Like

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

Use this formula:

=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 ?
:stuck_out_tongue:

If you want it to return a numeric (maybe easier to use in Unix later):

=if(B2+30<TODAY(), 1, 0)

1 = old
0 = not old