DateTime.Now.Compare(To)
.Compare(To) compares the TimeSpan between two different DateTime objects. The DateTime object in the "To" parameter is subtracted from the DateTime object calling the Compare(To) method. As an example: Date1 - Date2 would be expressed as Date1.Compare(Date2).
Applies To
- Convert.ToDateTime(Convert)
- DateTime.Now
- DateTime.Today
- Event.Form.MainGrid.Results.AddRow([IDColumn]).GetDateTime(Column)
- Event.Form.MainGrid.Results.GetMaximumDateTime(ColName)
- Event.Form.MainGrid.Results.GetMinimumDateTime(ColName)
- Event.Form.MainGrid.Results.GetRow(X).GetDateTime(Column)
- Event.Form.MainGrid.SelectedRow.GetDateTime(Column)
- Event.Form.Parent.MainGrid.Results.AddRow([IDColumn]).GetDateTime(Column)
- Event.Form.Parent.MainGrid.Results.GetMaximumDateTime(ColName)
- Event.Form.Parent.MainGrid.Results.GetMinimumDateTime(ColName)
- Event.Form.Parent.MainGrid.Results.GetRow(X).GetDateTime(Column)
- Event.Form.Parent.MainGrid.SelectedRow.GetDateTime(Column)
- Event.Form.Parent.GetDataTable([TableName]).AddRow([IDColumn]).GetDateTime(Column)
- Event.Form.Parent.GetDataTable([TableName]).GetMaximumDateTime(ColName)
- Event.Form.Parent.GetDataTable([TableName]).GetMinimumDateTime(ColName)
- Event.Form.Parent.GetDataTable([TableName]).GetRow(X).GetDateTime(Column)
- Event.Form.Parent.Grids(FID).Results.AddRow([IDColumn]).GetDateTime(Column)
- Event.Form.Parent.Grids(FID).Results.GetMaximumDateTime(ColName)
- Event.Form.Parent.Grids(FID).Results.GetMinimumDateTime(ColName)
- Event.Form.Parent.Grids(FID).Results.GetRow(X).GetDateTime(Column)
- Event.Form.Parent.Grids(FID).SelectedRow.GetDateTime(Column)
- Event.Form.GetDataTable([TableName]).AddRow([IDColumn]).GetDateTime(Column)
- Event.Form.GetDataTable([TableName]).GetMaximumDateTime(ColName)
- Event.Form.GetDataTable([TableName]).GetMinimumDateTime(ColName)
- Event.Form.GetDataTable([TableName]).GetRow(X).GetDateTime(Column)
- Event.Form.Grids(FID).Results.AddRow([IDColumn]).GetDateTime(Column)
- Event.Form.Grids(FID).Results.GetMaximumDateTime(ColName)
- Event.Form.Grids(FID).Results.GetMinimumDateTime(ColName)
- Event.Form.Grids(FID).Results.GetRow(X).GetDateTime(Column)
- Event.Form.Grids(FID).SelectedRow.GetDateTime(Column)
- Inventory.LotExplosion(Lots[, View, EndDate, NegativeLots, ByProducts]).AddRow([IDColumn]).GetDateTime(Column)
- Inventory.LotExplosion(Lots[, View, EndDate, NegativeLots, ByProducts]).GetMaximumDateTime(ColName)
- Inventory.LotExplosion(Lots[, View, EndDate, NegativeLots, ByProducts]).GetMinimumDateTime(ColName)
- Inventory.LotExplosion(Lots[, View, EndDate, NegativeLots, ByProducts]).GetRow(X).GetDateTime(Column)
- InventoryLot.ExpirationDate
- InventoryLot.LotDate
- Parameters.Results.AddRow([IDColumn]).GetDateTime(Column)
- Parameters.Results.GetMaximumDateTime(ColName)
- Parameters.Results.GetMinimumDateTime(ColName)
- Parameters.Results.GetRow(X).GetDateTime(Column)
- Query.GetDateTime(Query[, IsNull])
- Query.GetTable(Query).AddRow([IDColumn]).GetDateTime(Column)
- Query.GetTable(Query).GetMaximumDateTime(ColName)
- Query.GetTable(Query).GetMinimumDateTime(ColName)
- Query.GetTable(Query).GetRow(X).GetDateTime(Column)
- Script.GetDataTable(TableName).AddRow([IDColumn]).GetDateTime(Column)
- Script.GetDataTable(TableName).GetMaximumDateTime(ColName)
- Script.GetDataTable(TableName).GetMinimumDateTime(ColName)
- Script.GetDataTable(TableName).GetRow(X).GetDateTime(Column)
Properties and Methods
Properties
- .Days: (Int32) Returns the number of days from Math.Truncate(TotalDays).
- .Hours: (Int32) Returns the number of hours from Math.Truncate(TotalHours - (Days * 24)).
- .Milliseconds: (Int32) Returns the number of milliseconds from Math.Truncate(TotalMilliseconds - ((Days * 24 * 60 * 60 * 1000) + (Hours * 60 * 60 * 1000) + (Minutes * 60 * 1000) + (Seconds * 1000))).
- .Minutes: (Int32) Returns the number of minutes from Math.Truncate(TotalMinutes - ((Days * 24 * 60) + (Hours * 60))).
- .Seconds: (Int32) Returns the number of seconds from Math.Truncate(TotalSeconds - ((Days * 24 * 60 * 60) + (Hours * 60 * 60) + (Minutes * 60))).
- .Ticks: (Int64) Returns the total number of ticks between the two DateTime objects.
- .TotalDays: (Double) Returns the total number of days between the two DateTime objects. Partial days are expressed as a decimal.
- .TotalHours: (Double) Returns the total number of hours between the two DateTime objects. Partial hours are expressed as a decimal.
- .TotalMilliseconds: (Double) Returns the total number of milliseconds between the two DateTime objects. Partial milliseconds are expressed as a decimal.
- .TotalMinutes: (Double) Returns the total number of minutes between the two DateTime objects. Partial minutes are expressed as a decimal.
- .TotalSeconds: (Double) Returns the total number of seconds between the two DateTime objects. Partial seconds are expressed as a decimal.
Available
The .Compare(To) method is available in:
- 16.05.087
- 16.06.035
- 16.07.008
- 17.00.005
- All newer builds
Type
TimeSpan
Syntax
DateTime.Now.Compare(To);
Parameters
|
Parameter |
Required |
Description |
|---|---|---|
|
To |
Yes |
A DateTime object. If left null, then .Compare(To) returns null Non-DateTime objects generate a scripting error. |
|
.Property |
Yes |
One of the listed properties from above is required to return a result |
Example
var ldTest1 = new DateTime(2021, 10, 26, 10, 28, 24); //--10/26/2021 10:28:24
var ldTest2 = new DateTime(2019, 9, 1, 12, 30, 45); //--9/1/2019 12:30:45
var loInterval = ldTest1.Compare(ldTest2);
var lcOutput = 'Comparing ldTest1 (' + Convert.ToString(ldTest1) + ') to ldTest2 (' + Convert.ToString(ldTest2) + '):\r\n';
lcOutput += 'ldTest1.Compare(ldTest2).Days: ' + loInterval.Days + '\r\n';
lcOutput += 'ldTest1.Compare(ldTest2).TotalDays: ' + loInterval.TotalDays + '\r\n';
lcOutput += 'ldTest1.Compare(ldTest2).Hours: ' + loInterval.Hours + '\r\n';
lcOutput += 'ldTest1.Compare(ldTest2).TotalHours: ' + loInterval.TotalHours + '\r\n';
lcOutput += 'ldTest1.Compare(ldTest2).Minutes: ' + loInterval.Minutes + '\r\n';
lcOutput += 'ldTest1.Compare(ldTest2).TotalMinutes: ' + loInterval.TotalMinutes + '\r\n';
lcOutput += 'ldTest1.Compare(ldTest2).Seconds: ' + loInterval.Seconds + '\r\n';
lcOutput += 'ldTest1.Compare(ldTest2).TotalSeconds: ' + loInterval.TotalSeconds + '\r\n';
lcOutput += 'ldTest1.Compare(ldTest2).Milliseconds: ' + loInterval.Milliseconds + '\r\n';
lcOutput += 'ldTest1.Compare(ldTest2).TotalMilliseconds: ' + loInterval.TotalMilliseconds + '\r\n';
lcOutput += 'ldTest1.Compare(ldTest2).Ticks: ' + loInterval.Ticks;
Event.Form.MessageBox(lcOutput);
/* Expected Prompt response:
Comparing ldTest1 (10/26/2021 10:28:24) to ldTest2 (09/01/2019 12:30:45):
ldTest1.Compare(ldTest2).Days: 785
ldTest1.Compare(ldTest2).TotalDays: 785.9150347222222
ldTest1.Compare(ldTest2).Hours: 21
ldTest1.Compare(ldTest2).TotalHours: 18861.96083333333
ldTest1.Compare(ldTest2).Minutes: 57
ldTest1.Compare(ldTest2).TotalMinutes: 1131717.6500000001
ldTest1.Compare(ldTest2).Seconds: 39
ldTest1.Compare(ldTest2).TotalSeconds: 67903059
ldTest1.Compare(ldTest2).Milliseconds: 0
ldTest1.Compare(ldTest2).TotalMilliseconds: 67903059000
ldTest1.Compare(ldTest2).Ticks: 679030590000000
*/