locked
How to convert time(7) to System.DateTime? RRS feed

  • Question

  • User-618475340 posted

    In my database, there is a column, starttime, which is of datatype time(7).  It seemed my only option in creating the model was

    public DateTime starttime { get; set; }

    But it throws the error "The 'starttime' property on 'gigs' could not be set to a 'System.TimeSpan' value. You must set this property to a non-null value of type 'System.DateTime'.  How do I get it to accept the time(7) datatype?

    Friday, May 22, 2015 7:55 PM

Answers

  • User-1903718305 posted

    You can set default or system.Datetime value in Class Constructor as follows-

    class YourClass 
    {
        public YourClass()
        {
            starttime = DateTime.Now;
        }
        public DateTime starttime { get; set; }
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 22, 2015 8:14 PM