Sponsored Content
Top Forums Shell Programming and Scripting calcuate the week number of a given date Post 83004 by ahmedwaseem2000 on Friday 9th of September 2005 07:04:14 AM
Old 09-09-2005
Guys got the solution - i have added this if statement before calculation. please let me know if you find this is not good.

Code:
# !/bin/ksh

calcweek() {
if [ $LEAP -eq 0 ] ; then
   set -A DIM 0 0 31 59 90 120 151 181 212 243 273 304 334
else
   set -A DIM 0 0 31 60 91 121 152 182 213 244 274 305 335
fi
if [ $DD -eq 08 ];then
DD=8
elif [ $DD -eq 09 ];then
DD=9
fi
((JDAY=DIM[$MM]+DD))
echo $DD day $MM mon
echo $JDAY
((WEEK=(JDAY+$1)/7))
echo $YEAR-$WEEK
}

MM=$1
DD=$2
YEAR=$3

MMDD=$MM$DD
typeset -Z2 WEEK

((YEAR%100)) && ((LEAP=!(YEAR%4))) || ((LEAP=!(YEAR%400)))

cal 01 $YEAR |
  awk '{getline;getline;print NF;exit}' |
  read W1K

case $W1K$LEAP in
  70)  echo '0101 52 9999 5' ;;
  10)  echo '0102 XX 9999 4' ;;
  20)  echo '0103 53 9999 3' ;;
  30)  echo '0000 00 9999 9' ;;
  40)  echo '0000 00 1229 8' ;;
  50)  echo '0000 00 1230 7' ;;
  60)  echo '0000 00 1231 6' ;;
  71)  echo '0101 52 1231 5' ;;
  11)  echo '0102 52 9999 4' ;;
  21)  echo '0103 53 9999 3' ;;
  31)  echo '0000 00 9999 9' ;;
  41)  echo '0000 00 9999 8' ;;
  51)  echo '0000 00 1229 7' ;;
  61)  echo '0000 00 1230 6' ;;
esac | read JCUT PWK DCUT ADJ

if [ $MMDD -le $JCUT ] ; then
   if [ $PWK = 'XX' ] ; then
      ((PYEAR=YEAR-1))
      ((PYEAR%100)) && ((PLEAP=!(PYEAR%4))) || ((PLEAP=!
(PYEAR%400)))
      ((PWK=52+PLEAP))
   fi
   echo $((YEAR=YEAR-1))-$PWK
else
   if [ $MMDD -ge $DCUT ] ; then
      echo $((YEAR=YEAR+1))-01
   else
      calcweek $ADJ
   fi
fi

exit 0


Last edited by Perderabo; 09-09-2005 at 02:06 PM.. Reason: Switch quote tags to code tags for readability
 

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to obtain date and day of the week from `date` command

Hi, does anybody know how to format `date` command correctly to return the day of the week? Thanks -A I work in ksh.... (1 Reply)
Discussion started by: aoussenko
1 Replies

2. Shell Programming and Scripting

Date One Week Ago From Given Date, Not From Current Date

Hi all, I've used various scripts in the past to work out the date last week from the current date, however I now have a need to work out the date 1 week from a given date. So for example, if I have a date of the 23rd July 2010, I would like a script that can work out that one week back was... (4 Replies)
Discussion started by: Donkey25
4 Replies

3. Shell Programming and Scripting

Know the number of the week for a date

Hi, I tried to find the solution on the forum without success. datecalc from Perderabo doesn't solve my problem. I would like to know how to do the same thing that date +%U but for a specific date. For example: 2011 08 27 => 39 Thinks a lot (8 Replies)
Discussion started by: Castelior
8 Replies

4. Shell Programming and Scripting

Extract week start,end date from given date in PERL

Hi All, what i want to do in perl is i should give the date at run time .Suppose date given is 23/12/2011(mm/dd/yyyy) the perl script shold find week start date, week end date, previous week start date,end date,next week start date, end date. In this case week start date will be-:12/19/2011... (2 Replies)
Discussion started by: parthmittal2007
2 Replies

5. Shell Programming and Scripting

Week number from a date.

Hi, How can we get the week number from any paricular date. lets say date is 20120404 (YYYYMMDD) then how to get the week number? date +%W --- Thic command gives the week number for current date only. Thanks. (13 Replies)
Discussion started by: 46019
13 Replies

6. AIX

How to calcuate total number of weeks?

Hi anyone can help? How to calculate total number of weeks from a specify date, for example, 01 Jan 2012. Thx! https://www.unix.com/images/misc/progress.gif (1 Reply)
Discussion started by: rayray2013
1 Replies

7. Shell Programming and Scripting

Find week of the year for given date using date command inside awk

Hi all, Need an urgent help on the below scenario. script: awk -F"," 'BEGIN { #some variable assignment} { #some calculation and put values in array} END { year=#getting it from array and assume this will be 2014 month=#getting it from array and this will be 05 date=#... (7 Replies)
Discussion started by: vijaidhas
7 Replies
MSSQL_NUM_FIELDS(3)													       MSSQL_NUM_FIELDS(3)

mssql_num_fields - Gets the number of fields in result

SYNOPSIS
int mssql_num_fields (resource $result) DESCRIPTION
mssql_num_fields(3) returns the number of fields in a result set. PARAMETERS
o $result - The result resource that is being evaluated. This result comes from a call to mssql_query(3). RETURN VALUES
Returns the number of fields, as an integer. EXAMPLES
Example #1 mssql_num_fields(3) example <?php // Connect to MSSQL and select the database $link = mssql_connect('KALLESPCSQLEXPRESS', 'sa', 'phpfi'); mssql_select_db('php', $link); // Select some data from our database $data = mssql_query('SELECT [name], [age] FROM [php].[dbo].[persons]'); // Construct a table echo '<table border="1">'; $header = false; // Iterate through returned results while ($row = mssql_fetch_array($data)) { // Build the table header if (!$header) { echo '<thead>'; echo '<tr>'; for ($i = 1; ($i + 1) <= mssql_num_fields($data); ++$i) { echo '<td>' . ucfirst($row[$i]) . '</td>'; } echo '</tr>'; echo '</thead>'; echo '<tbody>'; $header = true; } // Build the row echo '<tr>'; foreach($row as $value) { echo '<td>' . $value . '</td>'; } echo '</tr>'; } // Close table echo '</tbody>'; echo '</table>'; // Clean up mssql_free_result($data); mssql_close($link); ?> SEE ALSO
mssql_query(3), mssql_fetch_field(3), mssql_num_rows(3). PHP Documentation Group MSSQL_NUM_FIELDS(3)
All times are GMT -4. The time now is 05:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy