Current Issue


Table of contents

CD-ROM

Sys Admin and The Perl Journal CD-ROM version 12.0

Version 12.0 delivers every issue of Sys Admin from 1992 through 2006 and every
issue of The Perl Journal from 1996-2002 in one convenient CD-ROM!

Order now!

Sys Admin Magazine > Archives > 2006 > June
SysAdminMag.com

Converting Dates to Week Dates

Ed Schaefer and John Spurgeon

Dates are often identified by a year, a month, and a day of the month. An alternative notation, common in European countries and in manufacturing industries, uses a year, a week number, and a day of the week to specify a date. The main difficulty with using weeks to specify a date is identifying when the first week of a year should begin. ISO, the International Standards Organization, created the ISO 8601 standard to reduce confusion in the area of date/time representations. Regarding week dates, the document states that calendar weeks start on Monday; weeks are numbered starting with the number one; and the first calendar week of a year is the week that includes the first Thursday of the year. Algorithms based on the ISO 8601 definition of a week have been developed to convert dates from year-month-day format to year-week-day format. One example is an algorithm described by Rick McCarty [1]. But what if the ISO 8601 definition of a week date doesn't apply? What if you are operating under the assumption that weeks start on Sunday, not Monday? What if January 1st must fall in the first calendar week of the year? We developed Korn shell script ymd2ywd (Listing 1) that converts a date in year-month-day format to an equivalent date in year-week-day format. The algorithm employed is similar to McCarty's. Both algorithms rely only on simple math functions and convert a wide range of dates. (Some algorithms rely on date arithmetic capabilities provided by the programming environment or significantly limit the range of dates that can be converted.) However, it is easy to configure our ymd2ywd script to account for various assumptions about when a week begins and what constitutes the first week of the year.




MarketPlace

Build IT Knowledge with Current & Trusted Content
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.

Six Sigma Certification
100% Online-Six Sigma Certificate from Villanova - Find Out More Now.

Workflow Enabled Help Desk & IT Service Management
Automate service desk activities and integrate processes across IT. Learn more here.

Flowcharts from C/C++ code -- Free trial download
Understand C/C++ code in less time. A new team member ? Inherited legacy code ? Get up to speed faster with Crystal Flow for C/C++. Code-formatting improves readability. Flowcharts are integrated with code browser. Export flowcharts to Visio.

Wanna see your ad here?