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
How to compare the dates.. suri.tyson Shell Programming and Scripting 4 10-22-2008 12:13 PM
compare dates... i_priyank Shell Programming and Scripting 3 09-21-2007 12:50 AM
compare dates ragha81 Shell Programming and Scripting 2 11-01-2006 06:17 PM
How to compare two dates bankpro High Level Programming 5 01-24-2006 04:07 AM
compare two dates wchen Shell Programming and Scripting 6 10-24-2002 04:39 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-08-2009
balaji23_d balaji23_d is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 4
Question compare between the two dates

Hi all,

How to check whether the given the two dates is minimal.

example:

Date 1 : 23-03-2008 with timestamp
Date 2: 20-03-2008 With tmestamp

I want to compare the twodates and which it gives the minimum date

i wnat to get the output like this below

output: the Date2 is minimum date
  #2 (permalink)  
Old 01-08-2009
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,884
Convert each to a YYYYMMDD string and compare:
Code:
date1num=`echo $date1 | awk -F- '{ print $3 $2 $1 }'`
date2num=`echo $date2 | awk -F- '{ print $3 $2 $1 }'`
if [ $date1num = $date2num]; then
   echo Dates are equal.
elif [ $date1num < $date2num ] ; then 
   echo "Date 1 is the minimum date"
else
   echo "Date 2 is the minimum date"
fi
Closed Thread

Bookmarks

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 07:14 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