I\'m trying to create a string from the DateTime object which yields the format mm:dd:yyyy
.
Conventionally the DateTime
object comes as
While in most cases I agree with Mark Byers, I had a situation where I needed to store a date time that was only ever granular to the hour. Storing minutes and seconds would not only be superfluous, but also inaccurate. The user simply selected a date and hour, so while the date and hour would be user selected, the minutes and seconds would be set to whatever the current time was.
Removing minutes and seconds is very easy in this case. Here is the code:
scheduledDate = scheduledDate.AddMinutes(
scheduledDate.Minute * -1).AddSeconds(
scheduledDate.Second * -1);
Then I store it in the DB as a full date time, with minutes and seconds always 0.