Sponsored Content
Top Forums Shell Programming and Scripting calcuate the week number of a given date Post 83039 by Perderabo on Friday 9th of September 2005 01:15:14 PM
Old 09-09-2005
Thanks for posting your final solution. I don't recall ever hearing of ISO week numbers before. So I will add this thread to our date arithmetic FAQ article. I found this page which has an on-line calculator for ISO week numbers.

For the record, here is a datecalc based solution. It emulates the behavior of the on-line calculator in that it outputs a year, a week number, and a day of week number...
Code:
#! /usr/bin/ksh
month=$1
day=$2
year=$3
typeset -Z2 fwk

function calcisoweek
{
        integer year month day dow1y mjd1y mjd isoweek
        year=$1
        month=$2
        day=$3
        dow1y=$(datecalc -d $year 1 1)
        ((dow1y=(dow1y+6)%7))
        mjd1y=$(datecalc -j $year 1 1)
        mjd=$(datecalc -j $year $month $day)
        ((isoweek=(mjd - mjd1y - dow1y + 7 + 3 )/7))
        echo $isoweek
        return 0
}

dow=$(datecalc -d $year $month $day)
((!dow)) && dow=7
fwk=$(calcisoweek $year $month $day)
if ((!fwk)) ; then
        ((year=year-1))
        fwk=$(calcisoweek $year 12 31)
fi
echo ${year}-W${fwk}-${dow}
exit 0

 

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
platform::shell(n)					       Tcl Bundled Packages						platform::shell(n)

__________________________________________________________________________________________________________________________________________________

NAME
platform::shell - System identification support code and utilities SYNOPSIS
package require platform::shell ?1.1.4? platform::shell::generic shell platform::shell::identify shell platform::shell::platform shell _________________________________________________________________ DESCRIPTION
The platform::shell package provides several utility commands useful for the identification of the architecture of a specific Tcl shell. This package allows the identification of the architecture of a specific Tcl shell different from the shell running the package. The only requirement is that the other shell (identified by its path), is actually executable on the current machine. While for most platform this means that the architecture of the interrogated shell is identical to the architecture of the running shell this is not generally true. A counter example are all platforms which have 32 and 64 bit variants and where a 64bit system is able to run 32bit code. For these running and interrogated shell may have different 32/64 bit settings and thus different identifiers. For applications like a code repository it is important to identify the architecture of the shell which will actually run the installed packages, versus the architecture of the shell running the repository software. COMMANDS
platform::shell::identify shell This command does the same identification as platform::identify, for the specified Tcl shell, in contrast to the running shell. platform::shell::generic shell This command does the same identification as platform::generic, for the specified Tcl shell, in contrast to the running shell. platform::shell::platform shell This command returns the contents of tcl_platform(platform) for the specified Tcl shell. KEYWORDS
operating system, cpu architecture, platform, architecture platform::shell 1.1.4 platform::shell(n)
All times are GMT -4. The time now is 02:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy