DateMath 1.3.1
dotnet add package DateMath --version 1.3.1
NuGet\Install-Package DateMath -Version 1.3.1
<PackageReference Include="DateMath" Version="1.3.1" />
<PackageVersion Include="DateMath" Version="1.3.1" />
<PackageReference Include="DateMath" />
paket add DateMath --version 1.3.1
#r "nuget: DateMath, 1.3.1"
#:package DateMath@1.3.1
#addin nuget:?package=DateMath&version=1.3.1
#tool nuget:?package=DateMath&version=1.3.1
Date Math
DateMath parses and applies Elasticsearch-style date math expressions in .NET. It supports expressions anchored to the current UTC time or a specific date, arithmetic with common date units, and rounding.
The package targets .NET Standard 2.0, making it compatible with modern .NET and .NET Framework 4.6.1 or later. Microsoft recommends .NET Framework 4.7.2 or later when consuming .NET Standard 2.0 libraries.
Installation
Install the package with the .NET CLI:
dotnet add package DateMath
Or with the NuGet Package Manager Console:
Install-Package DateMath
Usage
Expressions can use now as their anchor:
using DaleNewman;
DateMath.Parse("now", "yyyy-MM-dd h tt");
DateMath.Parse("now+11h", "yyyy-MM-dd h tt");
DateMath.Parse("now-13h+1y+1d-1s", "yyyy-MM-dd HH:mm:ss");
DateMath.Parse("now/d", "yyyy-MM-dd HH:mm:ss.fff");
A fixed anchor date is separated from its math expression by ||:
var result = DateMath.Parse("2016-12-31 1 PM||+11h", "yyyy-MM-dd h tt");
// 2017-01-01 12 AM
Use TryParse when you need to check whether parsing succeeded:
if (DateMath.TryParse("now+11h", out DateTime date))
{
// Use date.
}
Use Apply when you already have a date:
var date = new DateTime(2016, 12, 31, 9, 30, 2);
var newYears = DateMath.Apply(date, "+1d/y");
// 2017-01-01 00:00:00
Operators
| Unit | Meaning |
|---|---|
y |
Year |
M |
Month |
w |
Week |
d |
Day |
h |
Hour |
m |
Minute |
s |
Second |
Prefix a unit with + or - to add or subtract it, such as now-10d. Prefix it with / to round down, such as now/M for the start of the current month.
Common reporting ranges include:
| Range | Start | End |
|---|---|---|
| Last 10 days | now-10d |
now |
| Month to date | now/M |
now |
| Year to date | now/y |
now |
| Sliding 60-day window | now-30d |
now+30d |
See the tests for more examples, the changelog for release history, and the NuGet packaging guide for local release instructions.
Contributing
Issues and pull requests are welcome in the GitHub repository. Build and test locally with:
dotnet test --configuration Release
DateMath is licensed under the Apache License 2.0.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages (3)
Showing the top 3 NuGet packages that depend on DateMath:
| Package | Downloads |
|---|---|
|
Transformalize
Package Description |
|
|
Transformalize.Container.Autofac
Package Description |
|
|
Transformalize.Transform.DateMath
DateMath Transform for Transformalize |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on DateMath:
| Repository | Stars |
|---|---|
|
dalenewman/Transformalize
Configurable Extract, Transform, and Load
|
| Version | Downloads | Last Updated |
|---|---|---|
| 1.3.1 | 48 | 8/29/2026 |
| 1.3.0 | 43,898 | 8/30/2022 |
| 1.2.0 | 4,805 | 10/14/2020 |
| 1.1.0 | 8,400 | 12/23/2019 |
| 1.0.0 | 3,868 | 12/28/2016 |
| 0.2.0-beta | 1,309 | 12/12/2016 |
| 0.1.0-beta | 1,225 | 12/2/2016 |
| 0.0.5-beta | 1,253 | 12/2/2016 |
| 0.0.4-beta | 1,234 | 12/1/2016 |
| 0.0.3-beta | 1,265 | 12/1/2016 |
| 0.0.2-beta | 1,221 | 12/1/2016 |
| 0.0.1-beta | 1,243 | 11/30/2016 |