I want to somehow specify a time in my Datetime.Now
so for instance I know that
DateTime.Now.AddDays(-1);
will get the date for yesterday exactly 24hrs ago but I want to get the date for yesterday at a specific time, for instance 5pm.
I can't find anything useful in relation to this on StackOverflow, any suggestions?
Use:
DateTime.Now.Date.AddDays(-1).AddHours(17);
You can create an instance of TimeSpan
and delete/add in DateTime.Now
.
OR
DateTime dt = DateTime.Now.AddDays(-1);
DateTime newdt = New DateTime(dt.Year, dt.Month, dt.Day, 17, 0, 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With