Recent

Author Topic: Incrementing DateTime variable.  (Read 1963 times)

graemejc

  • New Member
  • *
  • Posts: 33
Incrementing DateTime variable.
« on: November 17, 2018, 07:27:03 pm »
There are lots of Inc... functions to allow me to increment a DateTime variable. But is there a function that allows me to increment by a number of days or years or milliseconds as I see fit? I can write one, but hoping it's been done before. Can't find any though.

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Incrementing DateTime variable.
« Reply #1 on: November 17, 2018, 07:29:16 pm »
In DateUtils:
Code: Pascal  [Select][+][-]
  1. { ---------------------------------------------------------------------
  2.     Increment/decrement functions.
  3.   ---------------------------------------------------------------------}
  4.  
  5. Function IncYear(const AValue: TDateTime; const ANumberOfYears: Integer ): TDateTime;
  6. Function IncYear(const AValue: TDateTime): TDateTime; // ; const ANumberOfYears: Integer = 1)
  7. // Function IncMonth is in SysUtils
  8. Function IncWeek(const AValue: TDateTime; const ANumberOfWeeks: Integer): TDateTime;
  9. Function IncWeek(const AValue: TDateTime): TDateTime; // ; const ANumberOfWeeks: Integer = 1)
  10. Function IncDay(const AValue: TDateTime; const ANumberOfDays: Integer): TDateTime;
  11. Function IncDay(const AValue: TDateTime): TDateTime; //; const ANumberOfDays: Integer = 1)
  12. Function IncHour(const AValue: TDateTime; const ANumberOfHours: Int64): TDateTime;
  13. Function IncHour(const AValue: TDateTime): TDateTime; //; const ANumberOfHours: Int64 = 1
  14. Function IncMinute(const AValue: TDateTime; const ANumberOfMinutes: Int64): TDateTime;
  15. Function IncMinute(const AValue: TDateTime): TDateTime; // ; const ANumberOfMinutes: Int64 = 1
  16. Function IncSecond(const AValue: TDateTime; const ANumberOfSeconds: Int64): TDateTime;
  17. Function IncSecond(const AValue: TDateTime): TDateTime; // ; const ANumberOfSeconds: Int64 = 1
  18. Function IncMilliSecond(const AValue: TDateTime; const ANumberOfMilliSeconds: Int64): TDateTime;
  19. Function IncMilliSecond(const AValue: TDateTime): TDateTime; // ; const ANumberOfMilliSeconds: Int64 = 1

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Incrementing DateTime variable.
« Reply #2 on: November 17, 2018, 08:31:17 pm »
There are lots of Inc... functions to allow me to increment a DateTime variable. But is there a function that allows me to increment by a number of days or years or milliseconds as I see fit? I can write one, but hoping it's been done before. Can't find any though.

If what you mean is something that would let you do p.e.:
    IncDateTime(ADateTime, 365, idtInDays)
then AFAIK it isn't available (yet?) though it should be easy to implement with a simple case statement and the functions of DateUtils.pas cited  by wp above.
« Last Edit: November 17, 2018, 08:39:31 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018