Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2002.07.15;
Скачать: CL | DM;

Вниз

Переменная типа Date ???   Найти похожие ветки 

 
DenNNis   (2002-07-03 08:32) [0]

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


 
MBo ©   (2002-07-03 08:36) [1]

RXLib IncMonth


 
Alx2 ©   (2002-07-03 08:37) [2]

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.

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


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

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


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

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


 
MBo ©   (2002-07-03 08:48) [5]

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;


 
Kaban ©   (2002-07-03 09:27) [6]

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


 
MBo ©   (2002-07-03 09:36) [7]

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



Страницы: 1 вся ветка

Текущий архив: 2002.07.15;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.01 c
3-47188
_dron_
2002-06-19 11:19
2002.07.15
Проблема с восприятием года в Dbase


1-47452
diMAN
2002-06-28 17:44
2002.07.15
Работа с rtf-файлами


3-47198
KVT2000
2002-06-18 11:35
2002.07.15
Ошибка запроса


6-47666
Maratus
2002-04-30 21:13
2002.07.15
Узнать имя хоста по IP


1-47384
Gari
2002-07-02 12:41
2002.07.15
Помогите, запарка.