s c h e m a t i c s : c o o k b o o k

/ TimeRecipes / Cookbook.TimeWeekOfTheYear

This Web


WebHome 
WebChanges 
TOC (with recipes)
NewRecipe 
WebTopicList 
WebStatistics 

Other Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Schematics


Schematics Home
Sourceforge Page
SchemeWiki.org
Original Cookbook
RSS

Scheme Links


Schemers.org
Scheme FAQ
R5RS
SRFIs
Scheme Cross Reference
PLT Scheme SISC
Scheme48 SCM
MIT Scheme scsh
JScheme Kawa
Chicken Guile
Bigloo Tiny
Gambit LispMe
GaucheChez

Lambda the Ultimate
TWiki.org

Week of the Year, and Day of the Week/Month/Year

Problem

Given a date, you need to find out what week of the year, day of the week, day of the month, or day of the year that the date falls on.

Solution

We'll use our good all friend SRFI 19, and by using date->string, with the appropriate conversion specifiers, we'll get what we want:

(require (lib "19.ss" "srfi"))

(let ((today (current-date)))
  (values
   (date->string today)
   (date->string today
                 "Week No.: ~V, day: (~w of week) (~d of month) 
                 (~j of year)")))

Note: there are several other specifiers that you can pass to date->string.

If what you need is the actual numbers, then you can extract this information from the date instance yourself:

(require (lib "19.ss" "srfi"))

(let ((today (current-date)))
  (values
   (date->string today)
   ;; `1' means `Monday' is the first day of the week:
   (date-week-number today 1)
   (date-week-day today)
   (date-day today)
   (date-year-day today)))

Discussion

If you are wondering what to use when you are using the Epoch (seconds) representation of the given date, then you should consider transforming your number of seconds to date, and then use this recipe. See recipe TimeEpochToTime to pass from seconds to dates.

See Also

SRFI 19: Time Data Types and Procedures

Comments here

-- FranciscoSolsona - 05 May 2004

CookbookForm
TopicType: Recipe
ParentTopic: TimeRecipes
TopicOrder: 070

 
 
Copyright © 2004 by the contributing authors. All material on the Schematics Cookbook web site is the property of the contributing authors.
The copyright for certain compilations of material taken from this website is held by the SchematicsEditorsGroup - see ContributorAgreement & LGPL.
Other than such compilations, this material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest