Top.Mail.Ru
Мастера DELPHI, Delphi programming community Титульная страница Поиск, карта сайта Написать письмо 
| Новости | Поиск | FAQ | Статьи | Книги | Новости VCL |
| Форумы ЧАТ | Орешник | KOL и MCK |
Форумы -» Основная («Начинающим»)/ Базы / WinAPI / Компоненты / Сети / Media / Игры / Corba и COM / KOL / FreePascal / .Net / Прочее / RSDN.ORG

« предыдущая ветвь | форум | следующая ветвь »

Переменная типа Date ??? [D5, Win2k]


DenNNis ©   (2002-07-03 08:32:00) 

Ситуация следующая: Есть переменная типа Date (число/месяц/год), к этой переменной мне надо прибавить целое число от 0 до 12 (т.е. месяц) и нада чтоб получилась переменная тожа типа Date
Например: 01/02/2002 + 12 и должно получится 01/02/2003, Как это сделать ??


MBo   (2002-07-03 09:36:00) [1]

Kaban
Не возражаю ;)


Kaban   (2002-07-03 09:27:00) [2]

2 MBo
IncMonth является стандартной функцией и к RxLib никакого отношения не имеет


MBo   (2002-07-03 08:48:00) [3]

function DaysPerMonth(AYear, AMonth: Integer): Integer;
const
DaysInMonth: array[1..12] of Integer =
(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
begin
Result := DaysInMonth[AMonth];
if (AMonth = 2) and IsLeapYear(AYear) then Inc(Result); { leap-year Feb is special }
end;


function IncDate(ADate: TDateTime; Days, Months, Years: Integer): TDateTime;
var
D, M, Y: Word;
Day, Month, Year: Longint;
begin
DecodeDate(ADate, Y, M, D);
Year := Y; Month := M; Day := D;
Inc(Year, Years);
Inc(Year, Months div 12);
Inc(Month, Months mod 12);
if Month < 1 then begin
Inc(Month, 12);
Dec(Year);
end
else if Month > 12 then begin
Dec(Month, 12);
Inc(Year);
end;
if Day > DaysPerMonth(Year, Month) then Day := DaysPerMonth(Year, Month);
Result := EncodeDate(Year, Month, Day) + Days + Frac(ADate);
end;


Alx2   (2002-07-03 08:45:00) [4]

>DenNNis (03.07.02 08:43)
Разве сложно завести массив из 12 элементов?
Ну и учесть еще високосность.


DenNNis   (2002-07-03 08:43:00) [5]

Alx2 ©, это понятно конечно, но в месяце то , то 30 дней, то 31, это мне придется еще определять какой месяц и сколько в нем дней


Alx2   (2002-07-03 08:37:00) [6]

TDateTime is a used by the date and time routines to hold date and time values.

Unit

System

type TDateTime = type Double;

Description

Most VCL objects represent date and time values using the TDateTime type. The integral part of a TDateTime value is the number of days that have passed since 12/30/1899.The fractional part of a TDateTime value is fraction of a 24 hour day that has elapsed.

Following are some examples of TDateTime values and their corresponding dates and times:

0 12/30/1899 12:00 am
2.75 1/1/1900 6:00 pm
-1.25 12/29/1899 6:00 am
35065 1/1/1996 12:00 am
To find the fractional number of days between two dates, simply subtract the two values, unless one of the TDateTime values is negative. Similarly, to increment a date and time value by a certain fractional number of days, add the fractional number to the date and time value if the TDateTime value is positive.
When working with negative TDateTime values, computations must handle time portion separately. The fractional part reflects the fraction of a 24-hour day without regard to the sign of the TDateTime value. For example, 6:00 am on 12/29/1899 is –1.25, not –1 + 0.25, which would be –0.75. There are no TDateTime values between –1 and 0.

Таким образом, достаточно увеличивать дату на необходимое количество дней.


MBo   (2002-07-03 08:36:00) [7]

RXLib IncMonth


Наверх

Титульная страница Поиск, карта сайта Написать письмо