The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
weird file list problem jmmora AIX 8 08-08-2008 11:18 AM
Weird crontab problem RobSand SUN Solaris 8 10-09-2007 05:12 PM
Weird problem with output from "date '+3600*%H+60*%M+%S' " m223464 Shell Programming and Scripting 5 02-16-2006 12:22 PM
weird problem with removing files rein UNIX for Advanced & Expert Users 2 08-15-2005 07:51 AM
Weird Problem??? danhodges99 UNIX for Dummies Questions & Answers 2 04-11-2003 11:05 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 03-11-2008
meeraKh meeraKh is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 13
Post Weird date difference problem

I am trying to find the difference in days between 2 dates.
I have to extract the 1st date from a filename, which i did using the awk command.
I have to compare this date to today's date and if the difference is greater than 30 days, do something, else do something else.

This is what i wrote


Code:

INVDATE=`echo "SHIP_606400_2008233202_20080206_070308083544.xml"|awk -F_ '{print $4}'`
echo $INVDATE
TODAY=`date +"%Y%m%d"`
echo $TODAY
(( diff=$TODAY-$INVDATE))
echo $diff
if [ $diff -gt 30 ]; then
     #do a
else
  #do b
fi
The result that I got was

Code:
20080206
20080311
105
The difference between the dates is not 105 days, but 34 days.

What am i doing wrong - I am pretty new to Shell programming and am learning through this site.

Thanks in advance.
 

Bookmarks

Tags
linux, mtime, perl, perl regex, regex, ubuntu

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0