Cal command
I was wondering if there is a possible way to figure out the julian date for a specific day. For example September 2nd 1984 is the 246th day. I want to be able to capture and use the 246 number. Also I have been using If statements (a ton of them) to figure out if a date is valid. Curious if there is a quick way. Im using /bin/bash. Here is a sample of my code If there a quicker way of figuring this out. Thanks
if [ $YR -gt `date +%Y` ] then echo "You entered $BIRTHDATE, which is a future date, please enter your birthdate in the form YYYYMMDD" elif [ $MTH -gt "12" ] || [ $MTH -eq 0 ] || [ $YR -eq 0 ] || [ $DAY -eq 0 ] then echo "You entered $BIRTHDATE, which is an invalid date. Please enter your birthdate in the form YYYYMMDD" |
Why not just check for the Julian day number and the return code from the date command:
Code:
rossy - trigger - Wed Jun 07 21:24:32 |
I tried
date -d 20060631 +%j and it still gave me a date. Anyway to generate an error? |
My version of date does the same, that is it doesn't return an error in case of an invalid date. However, if you do this:
Code:
mydate="20060632" (I am sure this can be programmed in a more efficient way, but I am not good at it) jlinkels |
I'd be interested to know what version you are using because it seems very odd behaviour for it to return another value - I'm using slack current with:
rossy - trigger - Thu Jun 08 20:06:38 ~> date --version date (GNU coreutils) 5.96 |
version
date (coreutils) 4.5.8 |
Quote:
Code:
$ date -d 19780319 +%j |
Got ne other suggestions?? My friend suggested using cal month year | grep day but i don't know how to use it effectively
|
jlinkels@jlinkels_lt:~$ date --version
date (coreutils) 5.2.1 Written by David MacKenzie. jlinkels@jlinkels_lt:~$ date -d 20060632 Sun Jul 2 00:00:00 CEST 2006 Weird uh? Blackout, doesn't my suggestion work then? You check whether the dat is valid, and then you output the julian date? jlinkels |
jinkel ure idea works but only after yr 1910. i need it to go till 0001
|
All times are GMT -5. The time now is 11:19 AM. |