Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Основная";
Текущий архив: 2002.07.15;
Скачать: [xml.tar.bz2];

Вниз

Переменная типа 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;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.46 MB
Время: 0.012 c
1-47341
ValeX
2002-07-01 15:53
2002.07.15
вопрос по TChart


1-47387
greenrul
2002-07-02 14:09
2002.07.15
Нажимаемый но невидимый


1-47454
JC
2002-06-27 16:31
2002.07.15
Как PopupMenu показать прямо под Edit ом?


14-47793
s@shka
2002-06-15 14:32
2002.07.15
OpenSSL в родном Delphi


3-47186
Link
2002-06-19 11:37
2002.07.15
Запрос





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский