To find out how many days have lapsed since January 1st. There is a easy method in Linux. That is using the cal command. For example, try the following :
$ cal -j 10 2005
October 2005
Sun Mon Tue Wed Thu Fri Sat
274
275 276 277 278 279 280 281
282 283 284 285 286 287 288
289 290 291 292 293 294 295
296 297 298 299 300 301 302
303 304
Since today is October 6th, as of January 1st 2005, 279 days have elapsed. The option -j displays the Julian date.
1 comments:
This also works:
echo $((`date +%j`))
Gives the number of days elapsed since January 1st of this year.
CAVEAT: Result has trailing zeros, which means some bash commands might interpret this output as octal...
echo $((`date --date="20080403" +%j`))
Same as before, but for the specified date (in format YYYYMMDD).
A solution (admittedly, not the minimal solution... others more simple might exist) to remove the trailing zeros: use gawk.
echo `date --date="20080304" +%j` | gawk '{ printf("%i\n",$1) ; }'
Post a Comment