How to get Julian date (Three digit) of a given date (Not current date)? I do not have root privilege - so can not use date -d. Assume that we have three variables year, month and date.
Thx
How to get Julian date (Three digit) of a given date (Not current date)? I do not have root privilege - so can not use date -d. Assume that we have three variables year, month and date.
Thx
Not sure what you mean by "Julian date (three digit)", but here's something that could be helpful - greg2jul.sh
.
greg2jul.sh 2017 05 04
#!/bin/ksh
echo "$1 $2 $3" | awk '
function date2julian(year, month, day, _m, _y)
{
_m=12 * year + month - 3
_y= _m / 12
return ( int( (734 * _m + 15) / 24 - 2 * _y + _y/4 - _y/100 + _y/400 + day + 1721119) )
}
{
print date2julian($1,$2,$3)
}'
By "Julian date (three digit)" I mean cumulative day of the year. If you enter date +%j you will get cumulative day of the year of thecurrent date. I want similar thing for some other date.
OK, this is not a Julian date - this the cumulative number of day since the begining of the year....
But you can utilize the gre2jul conversion and substraction for Jan/1 - using the same command line args as suggested originally:
#!/bin/ksh
echo "$1 $2 $3" | awk '
function date2julian(year, month, day, _m, _y)
{
_m=12 * year + month - 3
_y= _m / 12
return ( int( (734 * _m + 15) / 24 - 2 * _y + _y/4 - _y/100 + _y/400 + day + 1721119) )
}
{
print date2julian($1,$2,$3) - date2julian($1,1,1) -1
}'
Thanks. I modified it per my requirement, but it worked.
The linux date command - found on lots of non-linux boxes:
$ date +%j -d 1/10/2016
010
It always helps us to help you when you specify your OS and OS version...