DateTime.MinValue and SqlDateTime overflow

前端 未结 10 545
北恋
北恋 2021-02-01 00:44

I don\'t want to validate txtBirthDate so I want to pass DateTime.MinValue in database.

My code:

 if (txtBirthDate.Text == st         


        
10条回答
  •  遇见更好的自我
    2021-02-01 01:20

    use extensions

    public static class DateTimeExtensions
    {
        public static DateTime MinValue(this DateTime sqlDateTime)
        {
            return new DateTime(1900, 01, 01, 00, 00, 00);
        }
    }
    
    
    DateTime date = DateTime.Now;
    Console.WriteLine("Minvalue is {0} ", date.MinValue().ToShortDateString());
    

提交回复
热议问题