• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 536
  • Last Modified:

Week of the year

Can anybody please give me an example of how to use the weekoftheyear routine. I have read the help file and it is as clear as mud. I have a date in a dateTime picker and i need to calculate the week No for a choosen date. I can see there is a routine that i can use but i just cant figure out how to use it

Many thanks
0
Paul-Brooks
Asked:
Paul-Brooks
  • 3
2 Solutions
 
kretzschmarCommented:
how about the
WeekOfTheYear-function
declared in the dateUtils-unit?

from delphi-help
----------------------------------------------

Returns the week of the year represented by a TDateTime value.

Unit

DateUtils

Category

datetime routines

Delphi syntax:

function WeekOfTheYear(const AValue: TDateTime): Word; overload;
function WeekOfTheYear(const AValue: TDateTime; var AYear): Word; overload;

C++ syntax:

extern PACKAGE Word __fastcall WeekOfTheYear(const System::TDateTime AValue);

extern PACKAGE Word __fastcall WeekOfTheYear(const System::TDateTime AValue, Word &AYear);

Description

Call WeekOfTheYear to obtain the week of the year represented by a specified TDateTime value. WeekOfTheYear returns a value between 1 and 53.

AYear returns the year in which the specified week occurs. Note that this may not be the same as the year of AValue. This is because the first week of a year is defined as the first week with four or more days in that year. This means that if the first calendar day of the year is a Friday, Saturday, or Sunday, then for the first three, two, or one days of the calendar year, WeekOfTheYear returns the last week of the previous year. Similarly, if the last calendar day of the year is a Monday, Tuesday, or Wednesday, then for the last one, two, or three days of the calendar year, WeekOfTheYear returns 1 (the first week of the next calendar year).

Note:      WeekOfTheYear uses the ISO 8601 standard definition of a week. That is, a week is considered to start on a Monday and end on a Sunday.
Note:      WeekOfTheYear returns the same value as the WeekOf function.

-------------------------------------------------
meikl ;-)
0
 
atul_parmarCommented:
var
  w : word;
begin
  w := WeekOf(DateTimePicker1.Date);
  ShowMessage('Week no = ' + inttostr(w));
end;
0
 
atul_parmarCommented:
var
  w, y : word;
begin
  w := WeekOf(DateTimePicker1.Date);
  ShowMessage('Week no = ' + inttostr(w));
  w := WeekOfTheYear(DateTimePicker1.Date); // Returns same as above
  ShowMessage('Week no = ' + inttostr(w));
  w := WeekOfTheYear(DateTimePicker1.Date, y); // same as above but y will have the year in which the returned   ShowMessage('Week no = ' + inttostr(w) + ' Year=' + inttostr(y));
week falls. To see the effect of year (last call) set the date to 1 jan 2006 and then set it to 2 jan 2006
end;
0
 
atul_parmarCommented:
var
  w, y : word;
begin
  w := WeekOf(DateTimePicker1.Date);
  ShowMessage('Week no = ' + inttostr(w));
  w := WeekOfTheYear(DateTimePicker1.Date); // Returns same as above
  ShowMessage('Week no = ' + inttostr(w));
  w := WeekOfTheYear(DateTimePicker1.Date, y); // same as above but y will have the year in which the returned     week falls. To see the effect of year (last call) set the date to 1 jan 2006 and then set it to 2 jan 2006
ShowMessage('Week no = ' + inttostr(w) + ' Year=' + inttostr(y));
end;
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now