How to create midnight datetime

Midnight is the first one – It’s the very first second of the day, not the last.

var todayDateTime = DateTime.Today;
var Midnight = todayDateTime.AddSeconds(-1);
//Here are the results
Console.WriteLine($"Today {todayDateTime.ToString()}, Mid night {Midnight.ToString()}");

The output is this;

Today 10/8/2021 12:00:00 AM, Mid night 10/7/2021 11:59:59 PM
FavoriteLoadingAdd to favorites
Spread the love

Author: Shahzad Khan

Software developer / Architect