larry@zeek.UUCP (Larry Podmolik) (05/16/89)
I need a C function that, given a date, would return what day of the week it fell on. Of course, I didn't think to save it at the time. I seem to remember this coming up in comp.lang.c, but I can't be sure. If anybody out there has this, could you please e-mail it to me? Thanks in advance, Larry
kar@cs.rit.edu (05/19/89)
In article <234@zeek.UUCP> larry@zeek.UUCP (Larry Podmolik) writes: >I need a C function that, given a date, would return what day of the >week it fell on. ... Check out the February 1979 issue of Interface Age (page 75-79). They give algorithms for all sorts of time/date problems. I used one to do what you want to do, and needed only the additional knowledge of today's date and today's day of the week. Kenneth A. Reek Rochester Institute of Technology {harvard,rutgers}!rochester!ritcv!kar
rjd@occrsh.ATT.COM (Randy_Davis) (05/24/89)
In article <234@zeek.UUCP> larry@zeek.UUCP (Larry Podmolik) writes: |I need a C function that, given a date, would return what day of the |week it fell on. Of course, I didn't think to save it at the time. Well, this is not C, but it is a cheap and easy shell script that will do the same, based on the "cal" command. Randy Davis UUCP: ...(att!)ocrjd!randy ...(att!)occrsh!rjd --------------------------cut here-------------------------------------- # How this for simple - "dow", a simple day of week calculator, written 1/11/89 # by Randy Davis. Error checking and error messages added 3/9/89. USAGE="Usage: $0 month[1-12] day[1-31] year[00-99] - to calculate the day\nof week for a certain date." MONTH=$1 DAY=$2 YR=$3 case "$DAY" in [1-9]|[12][0-9]|3[01]) ;; *) echo $USAGE ; exit ;; esac case "$MONTH" in [1-9]|1[012]) ;; *) echo $USAGE ; exit ;; esac case "$YR" in [0-9][0-9]) ;; *) echo $USAGE ; exit ;; esac set `cal $MONTH 19$YR | egrep "^$DAY | $DAY | $DAY$"` for DOW in Sunday Monday Tuesday Wednesday Thursday Friday Saturday do if [ "$1" = "$DAY" ] then break fi shift done echo $DOW
morrell@hpsal2.HP.COM (Michael Morrell) (05/26/89)
/ hpsal2:comp.sources.wanted / rjd@occrsh.ATT.COM (Randy_Davis) / 7:46 am May 24, 1989 / In article <234@zeek.UUCP> larry@zeek.UUCP (Larry Podmolik) writes: |I need a C function that, given a date, would return what day of the |week it fell on. Of course, I didn't think to save it at the time. Well, this is not C, but it is a cheap and easy shell script that will do the same, based on the "cal" command. Randy Davis UUCP: ...(att!)ocrjd!randy ...(att!)occrsh!rjd [script deleted] ---------- Nice try, but the script unfortunately relies on each week in cal's output to have seven numbers in it. It fails on days in the first week of a month if it does not start on a Sunday (e.g., try "dow 5 1 89"). Michael
bink@aplcen.apl.jhu.edu (Ubben Greg) (05/28/89)
In article <9490003@hpsal2.HP.COM> (Michael Morrell) writes: > > Nice try, but the script unfortunately relies on each week in cal's output > to have seven numbers in it. It fails on days in the first week of a month > if it does not start on a Sunday (e.g., try "dow 5 1 89"). Well I guess this discussion gives me license to post the CAL|SED solution I mailed to the original poster (entirely useless for his application I'm sure) :-) No error-checking and inefficient, but correct none-the-less. # USAGE: dow [day [month [year]]] set `date +"${1:-%d} ${2:-%m} ${3:-19%y}"` cal $2 $3 | sed -n " s/.*/SunMonTueWedThuFriSat & / 1!s/.*\([A-Z]..\).\{18\} *$1 .*/\1/p " -- Greg Ubben "A SED fanatic" bink@aplcen.apl.jhu.edu