Consider an Excel sheet with one column of bad data. We have a table that can be used to correct the data. My code runs it by writing a new sheet containing the old sheet plus adding new columns of correct data for them to compare.
This date is fine and works but it makes the date/time into a format with 24-h time.
How can this be changed to use the preferred format?
newSheet.Cells[i + 2, 3] = drugorder.DATE;
newSheet.Cells[i + 2, 3].NumberFormat = "m/d/yyyy h:mm";
Apparently, the
hspecifier in an Excel date format will only use 12-hour time if you include anAM/PMspecifier in the number format as well.The seemingly logical
.NumberFormat = "m/d/yyyy h:mm"produces:While
.NumberFormat = "m/d/yyyy h:mm AM/PM"produces the intended: