typestar

DateOnly & TimeOnly in C#

Calendar dates and wall-clock times, without the fake midnight.

var today = new DateOnly(2026, 8, 1);
var release = new DateOnly(2026, 11, 10);

Console.WriteLine(release.DayOfWeek);
Console.WriteLine(today.AddMonths(2));

// DayNumber turns calendar distance into plain integers
var wait = release.DayNumber - today.DayNumber;
Console.WriteLine($"{wait} days to go");

var standup = new TimeOnly(9, 30);
Console.WriteLine(standup.AddHours(2.5));

How it works

  1. DateOnly carries no time, so date math stays honest.
  2. DayNumber subtraction turns a wait into plain integers.
  3. TimeOnly.AddHours(2.5) handles the fractional hour.

Keywords and builtins used here

The run, in numbers

Lines
12
Characters to type
382
Tokens
89
Three-star pace
95 tpm

At the three-star pace of 95 tokens a minute, this run takes about 56 seconds.

Type this snippet

Step 1 of 3 in Dates & times, step 7 of 17 in The .NET library.

← Previous Next →