Will repeated use of DateTime.Today negatively impact performance? Is saving the value in a variable more efficient?
I'm writing a few functions that will calculate a new date, based on today's date. To accomplish this I use DateTime.Today relatively often. I wondered if it's more efficient to save the value in a variable and use the variable over DateTime.Today, or is there no difference?
public static DateTime GetFirstDateInThePast()
{
var calculatedYear = DateTime.Today.Year;
var calculatedMonth = DateTime.Today.Month < 7 ? 1 : 7;
var day = 1;
return new DateTime(calculatedYear, calculatedMonth, day);
}
vs
public static DateTime GetFirstDateInThePast()
{
var today = DateTime.Today;
var calculatedYear = today.Year;
var calculatedMonth = today.Month < 7 ? 1 : 7;
var day = 1;
return new DateTime(calculatedYear, calculatedMonth, day);
}