ksh script: convert mm/dd/yyyy to julian??

ksh script: convert mm/dd/yyyy to julian??

Post by Ralf Draege » Tue, 23 Feb 1999 04:00:00




> Greetings,

> Anyone know the formula for this date conversion(mm/dd/yyyy to julian)??
> Or even possibly have a function already written?

> I am trying to code an airtight script to remove files based on their
> age.  The easiest way
> I came up with was converting current and file mod. date to julian.  The
> exceptions
> appear easier to code.

Here's a simple c-Program doing this. Called with no argument it returns
the julian date in days since 1.1.1900 or call it with parameters
YYYY MM DD to get the julian date to a specific date ...

Hope this helps, Ralf.
---8<---------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

long jdatum(int jahr, int monat, int tag)
{
   long c, y;
   if ( monat>2 )
   {
      monat -= 3;
   }
   else
   {
      monat += 9;
      jahr--;
   }
   tag += (153*monat+2)/5;
   c = (146097L*(((long)jahr) / 100L))/4L;
   y =   (1461L*(((long)jahr) % 100L))/4L;
   return c+y+(long)tag+1721119L;

Quote:}

int main(int argc, char *argv[])
{
   int jahr = 1996;
   struct tm *tms;
   time_t curr_time;
   int monat, tag;
   long erg;
        if ( argc == 4 )
        {
                jahr = atoi(argv[1]);
                monat = atoi(argv[2]);
                tag = atoi(argv[3]);
        }
        else
        {
                time(&curr_time);
                tms = localtime(&curr_time);
                jahr = tms->tm_year+1900;
                monat = tms->tm_mon+1;
                tag = tms->tm_mday;
        }
        erg = jdatum (jahr, monat, tag) - 2415021L;
        printf ("%i\n",erg);
Quote:}

---8<---------------------------
--

- Intraplan Consult Gmbh  Orleansplatz 5a  81667 Muenchen  +49 89 45911-0 -

God, root, what is the difference? -Pitr (www.userfriendly.org: 11/11/1998)