![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compare date from db2 table to yesterday's Unix system date | sasaliasim | Shell Programming and Scripting | 8 | 04-24-2008 03:04 AM |
| Perl: Extracting date from file name and comparing with current date | MKNENI | Shell Programming and Scripting | 4 | 03-26-2008 12:01 PM |
| date issue-find prevoius date in a patricular format | bsandeep_80 | UNIX for Advanced & Expert Users | 3 | 11-15-2007 04:42 PM |
| Changing Creation Date to a Prespecified Date of a File In Unix | monkfan | UNIX for Dummies Questions & Answers | 4 | 11-28-2006 03:15 AM |
| [kornshell] Getting the next weekday date | rs_f01 | UNIX for Dummies Questions & Answers | 1 | 08-09-2005 08:34 PM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
How to get the weekday of the given date?
Hi All,
Thanks in Advance. I want a function/script which returns the weekday of the given date. the input to the function/script is the date with format MM/DD/YYYY, it should return the weekday as 1 for sunday, 2 for monday .......7 for saturday. ex: if the function called like this date_func 12/15/2005 it should return 5 (thursday) your help will be greatly appreciated Regards, Rinku |
| Forum Sponsor | ||
|
|
|
|||
|
one more way,
not thoroughly tested Code:
>cat weekday
# !/usr/bin/bash
weekday=$1
month=`echo ${weekday:0:2}`
day=`echo ${weekday:3:2}`
year=`echo ${weekday:6:4}`
weekday=1
for dayval in `cal $month $year | grep $day`
do
if [ $day -ne $dayval ]
then
weekday=$(($weekday + 1))
else
break
fi
done
echo "weekday is $weekday"
exit 0
|
|
|||
|
hi,
just saw the datecalc...was checking the julian day option for the same.If i want to find todays julian day using "date" command the output is: $date +%j $350 but if i use datecalc for calculating todays julian day: $datecalc -j 2005 12 16 $53720 just wondering what the output means here would be great if someone can throw some light on the same regards, Bhups |
|
||||
|
http://en.wikipedia.org/wiki/Julian_day
First of all, "The Julian day or Julian day number (JDN) is the number of days that have elapsed since 12 noon Greenwich Mean Time (UT or TT) on Monday, January 1, 4713 BC in the proleptic Julian calendar." datecalc is using the modified julian day number: "The Modified Julian Day (MJD), introduced by the Smithsonian Astrophysical Observatory in 1957 to record the orbit of Sputnik, is defined in terms of the Julian day as follows: MJD = JD - 2400000.5 The offset of 0.5 means that MJD started at midnight at the beginning of November 17, 1858, and that every Modified Julian Day begins and ends at midnight UT or TT." The author of the date program you are using has confused day-of-year with julian day: "The use of Julian date to refer to the day-of-year (ordinal date) is usually considered to be incorrect." |
|
|||
|
hi Perderabo,
thanks for the info so my next obvious question in my scripts i always come across this prob of converting julain date (CCYY DDD) to the MM DD YY format, so it would be a great help if i could use datecalc for the same purpose thanks in advance... regards, Bhups. |