<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: compare 2 dates .. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-dates/m-p/2553313#M28413</link>
    <description>Hi Richard,&lt;BR /&gt;&lt;BR /&gt;I have the perfect answer for this. The way to do this is convert a MM DD YYYY into a Julian Day (~ days since 01/01/4712 BCE - used by astronomers to make calculations easy).&lt;BR /&gt;&lt;BR /&gt;Use it like this:&lt;BR /&gt;DAY1=`caljd.sh 07/16/2001`&lt;BR /&gt;DAY2=`caljd.sh 07/19/2001`&lt;BR /&gt;&lt;BR /&gt;You can then do numerical operations on the two&lt;BR /&gt;values. The routine when supplied with 1 arg will assume that it is a Julian Day and convert it to a calander day. It's also very handy for taking a date and find out what the date is 37 days from then. You can also use it to determine the day of the week. caljd.sh -u will give full usage.&lt;BR /&gt;&lt;BR /&gt;Enjoy, Clay&lt;BR /&gt;</description>
    <pubDate>Mon, 16 Jul 2001 18:38:47 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2001-07-16T18:38:47Z</dc:date>
    <item>
      <title>compare 2 dates ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-dates/m-p/2553311#M28411</link>
      <description>Hey everyone &lt;BR /&gt;how would i go about comparing 2 dates for example:&lt;BR /&gt;DATE1=7-16-2001&lt;BR /&gt;DATE2=7-12-2001&lt;BR /&gt;if [$DATE1 &amp;gt; $DATE2]&lt;BR /&gt;then&lt;BR /&gt;    another command&lt;BR /&gt;else&lt;BR /&gt;    this command&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;I can get it to work with numbers but not dates.&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Richard</description>
      <pubDate>Mon, 16 Jul 2001 18:28:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-dates/m-p/2553311#M28411</guid>
      <dc:creator>someone_4</dc:creator>
      <dc:date>2001-07-16T18:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: compare 2 dates ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-dates/m-p/2553312#M28412</link>
      <description>Hi Richard:&lt;BR /&gt;&lt;BR /&gt;In the example, with the format you cited, do:&lt;BR /&gt;&lt;BR /&gt;if [ $DATE1 -gt $DATE2 ]&lt;BR /&gt;&lt;BR /&gt;...but it's better to test date relationships by constructing the date as CCYYMMDD.  So, in this case, I'd use 'cut' or 'awk' to rearrange the string before testing it.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 16 Jul 2001 18:35:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-dates/m-p/2553312#M28412</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-07-16T18:35:19Z</dc:date>
    </item>
    <item>
      <title>Re: compare 2 dates ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-dates/m-p/2553313#M28413</link>
      <description>Hi Richard,&lt;BR /&gt;&lt;BR /&gt;I have the perfect answer for this. The way to do this is convert a MM DD YYYY into a Julian Day (~ days since 01/01/4712 BCE - used by astronomers to make calculations easy).&lt;BR /&gt;&lt;BR /&gt;Use it like this:&lt;BR /&gt;DAY1=`caljd.sh 07/16/2001`&lt;BR /&gt;DAY2=`caljd.sh 07/19/2001`&lt;BR /&gt;&lt;BR /&gt;You can then do numerical operations on the two&lt;BR /&gt;values. The routine when supplied with 1 arg will assume that it is a Julian Day and convert it to a calander day. It's also very handy for taking a date and find out what the date is 37 days from then. You can also use it to determine the day of the week. caljd.sh -u will give full usage.&lt;BR /&gt;&lt;BR /&gt;Enjoy, Clay&lt;BR /&gt;</description>
      <pubDate>Mon, 16 Jul 2001 18:38:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-dates/m-p/2553313#M28413</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2001-07-16T18:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: compare 2 dates ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-dates/m-p/2553314#M28414</link>
      <description>you could just break the date down into 3 separate variables for each date (6 total) and compare each using nested if statements.  Kinda long, but it would definately work.&lt;BR /&gt;</description>
      <pubDate>Mon, 16 Jul 2001 18:39:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-dates/m-p/2553314#M28414</guid>
      <dc:creator>Mark Stewart</dc:creator>
      <dc:date>2001-07-16T18:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: compare 2 dates ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-dates/m-p/2553315#M28415</link>
      <description>Hi Richard,&lt;BR /&gt;&lt;BR /&gt;This is a example for you.&lt;BR /&gt;This is script find date a given number of days ago :&lt;BR /&gt;===========================================&lt;BR /&gt;set printnums = 0&lt;BR /&gt;&lt;BR /&gt;# Check for -n switch. Print day &amp;amp; month in numbers rather than word (i.e. 0-6 and 1-12)&lt;BR /&gt;if ("$1" == "-n") then&lt;BR /&gt;  set printnums = 1&lt;BR /&gt;  shift&lt;BR /&gt;endif&lt;BR /&gt;if ("$2" == "-n") set printnums = 1&lt;BR /&gt;&lt;BR /&gt;@ offset = `echo $1 | awk '{printf("%d",$0)}'`&lt;BR /&gt;&lt;BR /&gt;if ($offset &amp;lt; 1) then&lt;BR /&gt;  echo "Usage: `basename $0` [-n] &lt;NUMER of="" days=""&gt;"&lt;BR /&gt;  exit 1&lt;BR /&gt;endif&lt;BR /&gt;&lt;BR /&gt;if ($offset &amp;gt; 730000) then&lt;BR /&gt;  echo "Get real.  This is before the birth of Christ."&lt;BR /&gt;  exit 1&lt;BR /&gt;endif&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;@ year = `date +'%Y'`&lt;BR /&gt;@ newyear = $year&lt;BR /&gt;set dayname = `date +'%a'`&lt;BR /&gt;set newdayname = $dayname&lt;BR /&gt;@ monthnum = `date +'%m'` &lt;BR /&gt;@ newmonthnum = $monthnum&lt;BR /&gt;set month = `date +'%b'`&lt;BR /&gt;set newmonth = $month&lt;BR /&gt;@ datenum = `date +'%e'`&lt;BR /&gt;@ newdatenum = $datenum&lt;BR /&gt;@ daynum = `date +'%u'`&lt;BR /&gt;@ newdaynum = $daynum&lt;BR /&gt;&lt;BR /&gt;if (($datenum - $offset) &amp;gt; 0) then    # If same month&lt;BR /&gt;  @ newdatenum = ($datenum - $offset)&lt;BR /&gt;else       # Otherwise ...&lt;BR /&gt;  @ newdatenum = ($datenum - $offset) # newdatenum is now negative&lt;BR /&gt;  while ($newdatenum &amp;lt; 1)&lt;BR /&gt;    @ monthnum--&lt;BR /&gt;    if ($monthnum &amp;lt; 1) then&lt;BR /&gt;      @ monthnum = 12&lt;BR /&gt;      @ newyear--&lt;BR /&gt;    endif&lt;BR /&gt;    set newmonth = `echo $monthnum | awk 'BEGIN{month[1]="Jan";month[2]="Feb";month[3]="Mar";month[4]="Apr";month[5]="May"; month[6]="Jun";month[7]="Jul";month[8]= "Aug";month[9]="Sep";month[10]="Oct"; month[11]="Nov";month[12]="Dec"}{print month[$0]}'`&lt;BR /&gt;    switch ($newmonth)&lt;BR /&gt;      case Apr:&lt;BR /&gt;      case Jun:&lt;BR /&gt;      case Sep:&lt;BR /&gt;      case Nov:&lt;BR /&gt;        @ newdatenum += 30&lt;BR /&gt;        breaksw&lt;BR /&gt;      case Feb:&lt;BR /&gt;        if (($newyear % 4) == 0) then&lt;BR /&gt;          @ newdatenum += 29  # Leap year&lt;BR /&gt;        else&lt;BR /&gt;          @ newdatenum += 28  # Non leap year&lt;BR /&gt;        endif&lt;BR /&gt;        breaksw&lt;BR /&gt;      default:&lt;BR /&gt;        @ newdatenum += 31&lt;BR /&gt;      endsw&lt;BR /&gt;  end&lt;BR /&gt;endif&lt;BR /&gt;&lt;BR /&gt;# Calc dayname&lt;BR /&gt;@ tmp = ($offset % 7)&lt;BR /&gt;if (($daynum - $tmp) &amp;gt;= 0) then&lt;BR /&gt;  @ daynum -= $tmp&lt;BR /&gt;else&lt;BR /&gt;  @ daynum += (7 - $tmp)&lt;BR /&gt;endif&lt;BR /&gt;set newdayname = `echo $daynum | awk 'BEGIN{day[0]="Sun";day[1]="Mon";day[2]="Tue";day[3]="Wed";day[4]="Thu"; day[5]="Fri";day[6]="Sat";day[7]="Sun"}{print day[$0]}'`&lt;BR /&gt;&lt;BR /&gt;# Print results&lt;BR /&gt;if ($printnums == 1) then&lt;BR /&gt;  printf "%.1d %.2d %.2d %.4d\n" $daynum $monthnum $newdatenum $newyear&lt;BR /&gt;else&lt;BR /&gt;  printf "%3s %3s %2d %4d\n" $newdayname $newmonth $newdatenum $newyear&lt;BR /&gt;endif&lt;BR /&gt;&lt;BR /&gt;exit 0&lt;BR /&gt;==============================================&lt;BR /&gt;&lt;BR /&gt;I think this help.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Abel Berger&lt;BR /&gt;  &lt;BR /&gt;&lt;BR /&gt;&lt;/NUMER&gt;</description>
      <pubDate>Mon, 16 Jul 2001 18:42:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-dates/m-p/2553315#M28415</guid>
      <dc:creator>Abel Berger</dc:creator>
      <dc:date>2001-07-16T18:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: compare 2 dates ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-dates/m-p/2553316#M28416</link>
      <description>I have this script where I check/compare for dates it is in perl. I am just copying whole script. I am not good programmer. but it works fine for me.&lt;BR /&gt;&lt;BR /&gt;#!/usr/local/bin/perl&lt;BR /&gt;chomp @listsystems = ( list of systems);&lt;BR /&gt;%User = ();&lt;BR /&gt;&lt;BR /&gt;open(FILE,"&amp;gt;who.list")|| die "who.list cannot be opened\n";&lt;BR /&gt;&lt;BR /&gt;chomp($Curr_Month = `/usr/bin/date +%b`);&lt;BR /&gt;chomp($Curr_Date = `/usr/bin/date +%d`);&lt;BR /&gt;chomp($Curr_Weekday = `/usr/bin/date +%u`);&lt;BR /&gt;&lt;BR /&gt;  print FILE "#$system\n";&lt;BR /&gt;  @whoinfo = `remsh $system -n who -u |grep old |sort`;&lt;BR /&gt;  foreach (@whoinfo){&lt;BR /&gt;    if (/console/) {&lt;BR /&gt;       next;&lt;BR /&gt;    }&lt;BR /&gt;    ($uname,$t2,$Month,$Date,$t3,$t4,$pid,$t6) = split(/\s+/,$_);&lt;BR /&gt;    $result=`remsh $system -n ps -ef |grep $pid|grep $uname`;&lt;BR /&gt;#    print "$uname   $pid  $system\n";&lt;BR /&gt;#    print "$result\n";&lt;BR /&gt;#    $wait=&lt;STDIN&gt;;&lt;BR /&gt;    if ($result eq ""){ #checking for valid login&lt;BR /&gt;       next;&lt;BR /&gt;    }&lt;BR /&gt;    if ($Month ne $Curr_Month){&lt;BR /&gt;       if ($Curr_Date &amp;gt; 10){ &lt;BR /&gt;         $User{$uname}++;&lt;BR /&gt;         print FILE "$_";&lt;BR /&gt;         next;&lt;BR /&gt;       }&lt;BR /&gt;       if ($Curr_Date &amp;lt; 10 &amp;amp;&amp;amp; $Date &amp;lt; 25){&lt;BR /&gt;         $User{$uname}++;&lt;BR /&gt;         print FILE "$_";&lt;BR /&gt;         next;&lt;BR /&gt;       }&lt;BR /&gt;    }&lt;BR /&gt;    if ($Curr_Date &amp;gt; 15 &amp;amp;&amp;amp; $Date &amp;lt; 5){&lt;BR /&gt;          #print "2";&lt;BR /&gt;          chomp;&lt;BR /&gt;          $User{$uname}++;&lt;BR /&gt;          print FILE "$_       more then 10 Days old\n";&lt;BR /&gt;          next;&lt;BR /&gt;    }&lt;BR /&gt;    if ($Curr_Date &amp;gt; 20 &amp;amp;&amp;amp; $Date &amp;lt; 10){&lt;BR /&gt;          chomp;&lt;BR /&gt;          $User{$uname}++;&lt;BR /&gt;          print FILE "$_       more then 10 Days old\n";&lt;BR /&gt;          next;&lt;BR /&gt;    }&lt;BR /&gt;    &lt;BR /&gt;   }#whoinfo&lt;BR /&gt;}#listsystems&lt;BR /&gt;close(FILE);&lt;BR /&gt;foreach $user (sort keys %User){&lt;BR /&gt;  open(FILE,"who.list")||die "Can't open who.list file\n";&lt;BR /&gt;  open(TEMP,"&amp;gt;user.old")|| die "Can't open user.old file\n";&lt;BR /&gt;  $sum=0;&lt;BR /&gt;  print TEMP "Following are your old logins check them and kill them if necessary\n";&lt;BR /&gt;  print TEMP "using listed PID \n";&lt;BR /&gt;  print TEMP "If you are not able to logout or kill them contact support\n\n"; &lt;BR /&gt;  print TEMP "NAME        LINE        TIME          IDLE    PID  COMMENTS\n";&lt;BR /&gt;  $found=0;&lt;BR /&gt;&lt;BR /&gt;  while(&lt;FILE&gt;){&lt;BR /&gt;    ($uname,$t2) = split(/\s+/,$_);&lt;BR /&gt;    if (/^#/) {&lt;BR /&gt;     $sysname=$_;&lt;BR /&gt;     $sysname_print=1;   #print sys name if it is new system &lt;BR /&gt;    }&lt;BR /&gt;    if ($user eq $uname){&lt;BR /&gt;      if ($sysname_print == 1){ # print system name and &lt;BR /&gt;        print TEMP "\n$sysname";&lt;BR /&gt;        $sysname_print=0;  # make variable =0 so next time it will not print sysname &lt;BR /&gt;      }&lt;BR /&gt;      $found=1;&lt;BR /&gt;      print TEMP "$_";&lt;BR /&gt;      $sum++;&lt;BR /&gt;    }&lt;BR /&gt;  } #while&lt;BR /&gt;&lt;BR /&gt;  print TEMP "\n\nThanks for your help\n\n\n";&lt;BR /&gt;  close(TEMP);&lt;BR /&gt;  close(FILE);&lt;BR /&gt;#  $user1="sachin";&lt;BR /&gt;  if ($found == 1){  # send mail only if found any old login&lt;BR /&gt;#    print "send to $user";&lt;BR /&gt;    system("/usr/bin/cat /home/sachin/myscript/cronjobs/user.old");&lt;BR /&gt;    system("/usr/bin/cat /home/sachin/myscript/cronjobs/user.old | /bin/mailx -s 'OLD LOGIN' $user");&lt;BR /&gt;  }&lt;BR /&gt;#$wait=&lt;STDIN&gt;;&lt;BR /&gt;}#foreach&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/STDIN&gt;&lt;/FILE&gt;&lt;/STDIN&gt;</description>
      <pubDate>Mon, 16 Jul 2001 18:47:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-dates/m-p/2553316#M28416</guid>
      <dc:creator>Sachin Patel</dc:creator>
      <dc:date>2001-07-16T18:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: compare 2 dates ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-dates/m-p/2553317#M28417</link>
      <description>Hi (again) Richard:&lt;BR /&gt;&lt;BR /&gt;Oops!  I missed that fact that you were comparing stings, not integers.  You could strip the "-" out and compare as two numbers or extract and rearrange before comparing:&lt;BR /&gt;&lt;BR /&gt;# X=`echo $DATE1|tr -d "-"`&lt;BR /&gt;# Y=`echo $DATE2|tr -d "-"`&lt;BR /&gt;&lt;BR /&gt;...or:&lt;BR /&gt;&lt;BR /&gt;# X=`echo $DATE1|awk -F- '{print $3 $1 $2}'`&lt;BR /&gt;# Y=`echo $DATE2|awk -F- '{print $3 $1 $2}'`&lt;BR /&gt;&lt;BR /&gt;...and then test as integers:&lt;BR /&gt;&lt;BR /&gt;if [ $X -gr $Y ]&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 16 Jul 2001 19:04:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-dates/m-p/2553317#M28417</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-07-16T19:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: compare 2 dates ..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-dates/m-p/2553318#M28418</link>
      <description>Hi again Richard,&lt;BR /&gt;&lt;BR /&gt;I didn't notice a small mistake in my posting that I'm sure you've caught; it should be:&lt;BR /&gt;DAY1=`caljd.sh 07 16 2001` rather that 07/16/2001&lt;BR /&gt;&lt;BR /&gt;It needs the three args to know this a calendar date and I want a Julian Day rather than the reverse.&lt;BR /&gt;&lt;BR /&gt;Clay</description>
      <pubDate>Mon, 16 Jul 2001 19:28:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/compare-2-dates/m-p/2553318#M28418</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2001-07-16T19:28:59Z</dc:date>
    </item>
  </channel>
</rss>

