Julian to calendar date conversion

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Julian to calendar date conversion

  • Creator
    Topic
  • #48231
    Rob Galino
    Participant

      Is there a way to convert a julian date i.e. 363 to calendar date i.e. Thu Dec 29 10:57:56 HST 2005 easily in AIX?  Julian date is easily provided by using “date +%j”, calander date by just typing “date”.  

      I want to be able to refer to the julian date the convert back to calendar date.

      I have a cron script which does the following:

      DATE=`date +%Y%m%d`

      YESTERDAY=`expr $DATE – 1`

      # Copy charge file to out directory…

      cp $SOURCEDIR$YESTERDAY$FILENAME.* $HOMEDIR$ODIR

      Well, this works well until the last day 1st of every month.  I need a way to set the variable YESTERDAY to the true day before the last day of the month, i.e. if today is 20050301, YESTERDAY should be 20050228 but the current cron script sets YESTERDAY to 20050300 which is an invalid date…

      Thanks all,

      – Rob

    Viewing 0 reply threads
    • Author
      Replies
      • #58084
        Walter Ericson
        Participant

          Rob,

          I use a function in Unix AIX 5.2 (korn shell) to get the last day of the month:

          last_day_of_month()

          {

          /usr/bin/cal $1 $2 | /usr/bin/awk ‘{if ($NF) Last=$NF}

          END{printf(“%sn”,Last);}’;

          }

          Sample useage (in korn shell script):

          YESTERDAY=`last_day_of_month $LASTMONTH $YEAR`;

          You may have to find cal and awk on your system!!

          cal is a calender call, the $1 is month value and $2 is a year.  

          The awk command gets the last field with a value from the calender display.

          You will also have to put in conditions for first of the year.

          In tcl you can use something like

          hcitcl>clock format [clock scan “today -1 day”] -format %Y%m%d

          20051228

          The clock scan command will parse many words.

          I have not had any luck converting julian to YYYYMMDD.

          Walter Ericson

      Viewing 0 reply threads
      • The forum ‘Cloverleaf’ is closed to new topics and replies.