Sign in Join
Wiki copytemporary

TDateTime/fi

English · Suomi

TDateTime on yhdistelmä päiväyksestä ja ajasta. Se käyttää attribuutteina: vuotta, kuukautta, päivää, tuntia, minuuttia, sekuntia ja mikrosekunteja.

Hae tämänhetkinen aika

Käännösyksikön (unit) SysUtils funktio Now noutaa järjestelmän tämänhetkisen päivämäärän ja kellonajan.

pascal
 function Now : TDateTime;

TDateTimen lisääminen ja vähentäminen

Käännösyksikön DateUtils funktio DaysBetween kertoo montako päivää on kahden TDateTime-päivämäärän välillä.

pascal
  function DaysBetween ( const ToDate, FromDate : TDateTime ) : Integer;

Käännösyksikön DateUtils funktio WeeksBetween kertoo montako kokonaista viikkoa on kahden TDateTime-päivämäärän välillä.

pascal
  function WeeksBetween( const ToDate, FromDate : TDateTime ):Integer;
pascal

program DateProject1;

uses
  SysUtils,DateUtils;
const
  DateFormatChars = 'dd"/"mm"/"yyyy';
var
  DateTime1, DateTime2: TDateTime;
begin
  DateTime1 := now;
  DateTime2 := DateTime1 + 4*7;       //28 päivää myöhemmin
  WriteLn('Tämänhetkinen päivämäärä on '+ FormatDateTime( DateFormatChars, DateTime1 ));
  WriteLn('28 päivää myöhemmin päivämäärä on '+ FormatDateTime( DateFormatChars, DateTime2 ));
  WriteLn('Päivien lukumäärä on '+ ( DaysBetween( DateTime1 ,DateTime2)).ToString );
  WriteLn('Viikkojen määrä on '+ ( WeeksBetween( DateTime1 ,DateTime2)).ToString );
  ReadLn;
end.

Aseta päivämäärä

Käännösyksikön SysUtils funktio EncodeDate asettaa päiväyksen.

pascal
  function EncodeDate ( const Year, Month, Day : Word ) : TDateTime;

Vertaa kahta TDateTime-päivämäärää

pascal

program CompareTwoDateTime;

uses
  SysUtils, DateUtils;
var
   firstDate, secondDate: TDateTime;
begin
  firstDate := EncodeDate(2000, 2, 29);
  secondDate := EncodeDate(2018, 8, 11);
  if DaysBetween( firstDate, secondDate) = 0
    then WriteLn('Molemmat päivät ovat samat')
    else
      if firstDate < secondDate
        then WriteLn('Ensimmäinen päivämäärä on aikaisempi')
        else WriteLn('Ensimmäinen päivämäärä on myöhemmin');
  ReadLn;
end.

Katso myös


From the Free Pascal wiki, page "TDateTime/fi", as it stood on 2019-07-08 after a change by Djzepi, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .

Edited on wiki.freepascal.org by 1 person, 2018–2019

From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.

WhenWhoWhat changed
DjzepiCreated page
DjzepiTDateTimen lisääminen ja vähentäminen
Djzepi

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.