線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2141
推到 Plurk!
推到 Facebook!

如何判斷某日為全年第幾週

答題得分者是:hagar
kkccgg
初階會員


發表:50
回覆:54
積分:30
註冊:2002-07-28

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-04-23 14:11:52 IP:202.145.xxx.xxx 未訂閱
請問: 如何以Delphi作某日為全年第幾週之判斷 謝謝
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-04-23 14:17:18 IP:202.39.xxx.xxx 未訂閱
function WeekOfYear(ADate: TDateTime): word;
var
  d, m, y: word;
  FirstOfYear: TDateTime;
begin
  DecodeDate(ADate, y, m, d);
  FirstOfYear := EncodeDate(y, 1, 1);
  Result := Trunc(ADate - FirstOfYear) div 7   1;
end;
   
procedure TForm .Button Click(Sender: TObject);
begin
  ShowMessage(IntToStr(WeekOfYear(Date)));
end;
--- 每個人都是一本書
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-04-23 14:17:42 IP:147.8.xxx.xxx 未訂閱
From delphi help: WeekOfTheYear function 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.
chiehmin
高階會員


發表:13
回覆:134
積分:134
註冊:2002-05-23

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-04-23 14:18:21 IP:61.221.xxx.xxx 未訂閱
uses DateUtils; WeekOfTheYear(Date);
系統時間:2024-04-29 21:03:54
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!