I have a script that requires the use of DOY (as a variable) instead of YY/MM/DD. I already obtained these parameters from downloaded files and stored them as variables (i.e. $day, $month, $year).
Is there any simple script that I could incorporate in mine to do this job?
Is this a Perl script? Sounds like it if you are using the system command.
$ cat ./date_test.pl
#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw(strftime);
use Time::Local;
#If you just want the julian of the current system date
my $x;
$x = strftime("%j", localtime());
print "x = $x\n";
#If you want the julian of a specific date, let's say 2008-12-10
my $testdate;
my $yyyy = 2008;
my $mm = 12;
my $dd = 10;
$testdate = timelocal(0, 0, 0, $dd, $mm-1, $yyyy);
$x = strftime("%j", localtime($testdate));
print "x = $x\n";
exit 0;
$ ./date_test.pl
x = 351
x = 345
$ date -d "2008-12-16" +%j
351
$ date -d "2008-12-10" +%j
345
If this is a Perl script, and it looks like it is, I wouldn't recommend getting the date from the OS. Use Perl's built-in date functions if you are going to use Perl. It's more efficient and more portable. If you are going to call the OS for a simple thing like a date, then you might as well just use a shell script.