public static void Main()
AuditLog auditLog = new AuditLog() {Created = new DateTime(2022,12,1,13,1,0)};
auditLog.Created = auditLog.Created.Value.AddMilliseconds(567);
auditLog.Created = auditLog.Created.Value.AddMicroseconds(123);
var milliseconds1 = auditLog.Created.Value.GetMilliseconds();
var milliseconds2 = auditLog.Created.Value.GetMilliseconds7();
Console.WriteLine($" Precision {auditLog.Created,-22}{milliseconds1}");
Console.WriteLine($"Precision 7 {auditLog.Created,-22}{milliseconds2}");
Console.WriteLine($" Mimic SSMS {auditLog.Created.Value:MM/dd/yyyy hh:mm:ss.fffffff}");
public partial class AuditLog
public int Id { get; set; }
public string User { get; set; }
public DateTime? Created { get; set; }
public static class Extensions
public static int GetMilliseconds(this DateTime sender)
=> Convert.ToInt32(sender.TimeOfDay.Milliseconds.ToString() + sender.TimeOfDay.Microseconds.ToString());
public static int GetMilliseconds7(this DateTime sender)
=> Convert.ToInt32((sender.TimeOfDay.Milliseconds.ToString() + sender.TimeOfDay.Microseconds.ToString())