[lug] Date Conversion Routine

rm at mamma.varadinet.de rm at mamma.varadinet.de
Mon Jun 19 14:30:29 MDT 2000


On Mon, Jun 19, 2000 at 02:18:57PM -0600, David Morris wrote:
> I have a slight problem I hope the group can help me with:
> 
> I am working on a project that uses dates in both Year/Month/Day *and*
> Year/Day of Year formats.  I am writing a shell script that will take
> files with one of these two date formats as the filename, and sort the
> files into a directory structure based off of the date.
> 
> Unfortunately, we cannot control the filenames, so we have to deal
> with both. :(
> 
> The question:  In the shell script, I need to convert Day of Year to
> Month and Day, and the reverse.  I know linux can use the 'date -d ...',
> but I need this shell script to work with both LINUX and SunOS 5.6
> (Solaris 2.6).  Solaris does not allow the 'date -d ...' command, so I
> need an alternative.
> 
> Anyone on the group know of a UNIX command, awk script, small C
> program, etc. that can do this conversion?

May i point you to the Date::Calc module for Perl ?
(http://www.cpan.org/modules/by-module/Date/Date-Calc-4.3.tar.gz)

This is a perl module that can do quite some date juggling. It's  
actually  a C-library with perl wrapper code arround it. The lib
can be used 'standalone', so if you dread perl you could write your
own little C program for the conversion (or maybe even a bash 
plugin ;-)

 Ralf





More information about the LUG mailing list