Wednesday, August 24, 2011

more on date and old date

Hi,

I had to work with epoch dates, that was older than the current, struggled a bit.
check this,

#!/bin/bash
dt1=`date`
dt2=`date -d "$dt 1 hour ago"`

s1=`date -d "$dt1" +"%s"`
s2=`date -d "$dt2" +"%s"`

echo Now - $dt1
echo
echo "1 Hour Before   -- $dt2 : $s2"
echo "Now             -- $dt1 : $s1"


put whatever for 1 hour ago as (ago for old, just 1 hour for future, you can have day, minutes)

change dt1 for any date, here its current can be date by -d option


PS:
check good examples in the info pages, i checked this late.. :(
$info date examples