Date and time

  • 134 Views
  • Last Post 25 July 2020
Ragav posted this 02 June 2020

Hi Everyone  Need help regarding the below query 

How to add Date and Time in the Database? using entity framework. (SqlServer)

 

 

admin posted this 25 July 2020

for example

public class Order{
    public int OrderId {get;set;}
    public DateTime CreateDate {get;set;}
}

To save DateTime to your sql database

using (MyDbContext db = new MyDbContext){
    Order order = new Order() { OrderId = 1, DateCreate = DateTime.Now.Date };
    db.Order.Add(order);
    db.SaveChanges();
}
Close