Skip to content

Instantly share code, notes, and snippets.

@mreis1
Last active December 9, 2020 17:19
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 mreis1/181446e2ad7dc72bd5b322b47a703af6 to your computer and use it in GitHub Desktop.
Save mreis1/181446e2ad7dc72bd5b322b47a703af6 to your computer and use it in GitHub Desktop.
DaySpan in moment.js
var a = '01/01/2000 00:00:00'
var b = '02/01/2000 12:00:00'
var f = 'DD/MM/YYYY HH:mm:ss';
var a1 = moment(a,f);
var b1 = moment(b,f);
console.log(`From date = ` + a);
console.log(`To date = ` + b);
console.log(`Fractional days difference = ${b1.diff(a1,'days', true)} days`);
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
unit Unit1;
interface
uses
DateUtils, // Unit containing the DaySpan command
SysUtils,
Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm} // Include form definitions
procedure TForm1.FormCreate(Sender: TObject);
var
fromdate, toDate : TDateTime;
begin
// Set up our date variables
fromDate := EncodeDateTime(2000, 01, 01, 0, 0, 0, 0);
toDate := EncodeDateTime(2000, 01, 02, 12, 0, 0, 0);
// Display these dates and the days between them
ShowMessage('From date = '+DateTimeToStr(fromDate));
ShowMessage('To date = '+DateTimeToStr(toDate));
ShowMessage('Fractional days difference = '+
FloatToStr(DaySpan(toDate, fromDate))+' days');
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment