Skip to content

Instantly share code, notes, and snippets.

@an01f01
Created January 8, 2023 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save an01f01/f99b096f466af2e1ebc0a13d6d926108 to your computer and use it in GitHub Desktop.
Save an01f01/f99b096f466af2e1ebc0a13d6d926108 to your computer and use it in GitHub Desktop.
This is a short example on how to quickly format a current day
uses
System.DateUtils;
procedure FormatDateToString(): string;
var
CurrentDate: TDateTime;
FmtStngs: TFormatSettings;
begin
{ As a bonus using IncDay will get you any day from current date, such as yesterday would be IncDay(Now, -1) }
CurrentDate := IncDay(Now, 0);
FmtStngs := TFormatSettings.Create('en-US');
FmtStngs.ShortDateFormat := 'yyyy-MM-dd';
Result := DateToStr(CurrentDate, FmtStngs);
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment