Delphi/Lazarus: Date of yesterday
Question by Compi | Last update on 2021-04-02 | Created on 2017-02-25
Is there any way available for getting the date of yesterday using Delphi or Lazarus?
I know that I can get the current date using the function "now" respectively using FormatDateTime('yyyy-mm-dd', now). But what can I do to get yesterday's date?
Related Topics
MySQL: Write current Date or Time into Column
Tutorial | 0 Comments
PHP: Current Date and Time
Tutorial | 0 Comments
PHP: Determine Week Number
Tutorial | 0 Comments
JavaScript: Get current Date and Time
Tutorial | 1 Comment
Delphi/Lazarus: How to set up a Link to a Website in an Application
Tutorial | 0 Comments
Delphi/Lazarus: Display current Date and Time
Tip | 0 Comments
Delphi: Global Treatment of Errors (Exceptions)
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
In addition to the function "now", there is also a function called "yesterday" available which can be used in the same way.
This function returns the date of yesterday as DateTime in which the time is set to 0:00h. Here is a small example:
In order to use this function, you will have to add the unit DateUtils to your uses section.
If you want to calculate the exact time exactly 24 hours ago or if you want to go without the Yesterday-function, you can also just substract 1 from Now. Because TDateTime is a decimal number with the days encoded before the decimal separator (1 corresponds to one day) and the time behind, this can be done without any problems.
Last update on 2021-04-02 | Created on 2017-02-26