Archive

Archive for August 4, 2010

date comparision in unix/Shell Script using if

Example :
========
     DATE1=”20100920″ #Date Format:YYYYMMDD
     DATE2=”20100921″
     if [ $DATE1 -lt $DATE2 ]
     then
          echo “true”
     else
          echo “false”
     fi

Output:
======
     true

Advertisements
Categories: Technical, unix commands

Day of Given date in Unix

Example:
======
Date Format:”yyyymmdd”
     date +%a –date=”20100920″

Output:
======
Mon

Categories: Technical, unix commands

Loop through Dates in Shell script

Example:
=======
     FROM=”20100920″ #YYYYMMDD format
     TO=”20100922″
     for ((foldate=$FROM; $foldate <= $TO; foldate++))
     do
           echo $foldate
     done

Output:
======
     20100920
     20100921
     20100922

Categories: Technical, unix commands

Date Difference between two dates in Oracle SQL

No of Days between two dates in Oracle sql:
Example:
=======
     select to_date(‘2010-09-20′,’yyyy-mm-dd’) – to_date(‘2010-09-21′,’yyyy-mm-dd’) from dual

Output:
======
     -1

Categories: SQL, Technical