The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-16-2005
Registered User
 

Join Date: Dec 2005
Posts: 20
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 12-16-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,636
Look at datecalc
Reply With Quote
  #3 (permalink)  
Old 12-16-2005
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,448
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
Reply With Quote
  #4 (permalink)  
Old 12-16-2005
Registered User
 

Join Date: Dec 2005
Posts: 23
Question compairing datecalc o/p to "date +%j"

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
Reply With Quote
  #5 (permalink)  
Old 12-16-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,318
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."
Reply With Quote
  #6 (permalink)  
Old 12-16-2005
Registered User
 

Join Date: Dec 2005
Posts: 23
Question how to get day-of-year??

hi Perderabo,

thanks for the info ...i really use to think that julian day refer to (what you say) day-of-year...

so my next obvious question is how to get day-of-year from datecalc??

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.
Reply With Quote
  #7 (permalink)  
Old 12-16-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,318
Should Jan 1 be a zero or a one? Both schemes are in use.

Compute the mjd of January 1 for the year. (Should Jan 1 be 1? If so subtract one.) Subtract the result from the mjd of the date to get day-of-year.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:51 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0