c# - Get date part of date time -
i have web api controller need write date table.
i try this
[responsetype(typeof(timetable))] public ihttpactionresult poststartpause(timetable startpause) { if (!modelstate.isvalid) { return badrequest(modelstate); } if (modelstate.isvalid) { datetime dt = datetime.today.date; timetable c = (from x in db.timetables x.company == startpause.company && x.inn == startpause.inn select x).first(); c.startpause = startpause.startpause; c.today = dt; db.savechanges(); } //db.timetables.add(startpause); //db.savechanges(); return json(new { result = "success", message = "saved successfully" }); // return createdatroute("defaultapi", new { id = startpause.id }, startpause); }
for date part try use code
datetime dt = datetime.today.date;
but writes date , time
here timetable class
public partial class timetable { public int id { get; set; } public string company { get; set; } public string inn { get; set; } public string startday { get; set; } public string startpause { get; set; } public string endday { get; set; } public string endpause { get; set; } public nullable<system.datetime> today { get; set; } }
how can write date db?
you have check table schema on db server, apparently field datatype set datetime, instead can use date.
Comments
Post a Comment