Both implementations must return 1.5
From date = 01/01/2000
To date = 02/01/2000 12:00:00
Fractional days difference = 1.5 days
http://www.delphibasics.co.uk/RTL.asp?Name=DaySpan&ExpandCode1=Yes
Both implementations must return 1.5
From date = 01/01/2000
To date = 02/01/2000 12:00:00
Fractional days difference = 1.5 days
http://www.delphibasics.co.uk/RTL.asp?Name=DaySpan&ExpandCode1=Yes
| 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. |