I have some DateTime's that will be calculated in the format: dtDateTime.ToString("M/dd/yyyy h:mm:ss tt")
and I want to keep the ss
formatting but just set the value to zero. Example:
Before Change:
"7/14/2014 7:34:27 AM"
After Change:
"7/14/2014 7:34:00 AM"
What I have tried:
dtDateTime = my DateTime
TimeSpan secondsDifference = dtDateTime.Subtract(new System.DateTime(0, 0, 0, 0, 0, dtDateTime.Second)
dtDateTime = dtDateTime.Date - secondsDifference;
return dtDateTime.ToString("M/dd/yyyy h:mm:ss tt")
This gives me an error, on the dtDateTime.Subtract()
expression because this date is before 1970, when (I think) Unix Time stamping started. How can I simply set the seconds
part of dtDateTime
to 00
?
NB - code brevity is important. Thanks all.