DateTime.Now.AddDays(Days)
.AddDays(Days) adds the specified number of days to the DateTime object. To subtract days, simply supply the Days parameter with a negative number.
Note: The AddDays() method adds the days to the date or variable calling it. You cannot do something like this:
var ldToday = DateTime.Today;
var ldTomorrow = ldToday.AddDays(1);
IdToday will be the same as IdTomorrow.
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
None
Available
The .AddDays(Days) method is available in:
- 15.03.016
- All newer builds
Type
DateTime
Syntax
DateTime.Now.AddDays(Days);
Parameters
|
Parameter |
Required |
Description |
|---|---|---|
|
Days |
Yes |
An integer value. Can be positive or negative. Non-integers will generate a scripting error. |
Example
var ldNew = new DateTime('6/10/2021 12:34:56');
var ldNewA = new DateTime('6/10/2021 12:34:56').AddDays(1);
var ldNewB = new DateTime('6/10/2021 12:34:56').AddDays(10);
var ldNewC = new DateTime('6/10/2021 12:34:56').AddDays(100);
var ldNewD = new DateTime('6/10/2021 12:34:56').AddDays(1000);
var ldNewE = new DateTime('6/10/2021 12:34:56').AddDays(-10);
Event.Form.MessageBox('Add Days to ' + ldNew.ShortDateString + ':' +
'\n1 Day: ' + ldNewA.ShortDateString +
'\n10 Days: ' + ldNewB.ShortDateString +
'\n100 Days: ' + ldNewC.ShortDateString +
'\n1000 Days: ' + ldNewD.ShortDateString +
'\n-10 Days: ' + ldNewE.ShortDateString);
/* Expected prompt response:
Add Days to 06/10/2021:
1 Day: 06/11/2021
10 Days: 06/20/2021
100 Days: 09/18/2021
1000 Days: 03/06/2024
-10 Days: 05/31/2021
*/