-2

Data type in db is time(7)

Model class:

public DateTime intime { get; set;}
public DateTime out_time { get; set;}

Controller:

 DateTime newintime = DateTime.Parse(Request["intime"]);

 DateTime newouttime = DateTime.Parse(Request["out_time "]);
 model =  db.bookm.Where(x=>x.intime>= newintime && x.out_time <= newouttime ).First();

If I convert to string it works . I want to insert it as for eg(18:23:44)

Rahatur
  • 3,147
  • 3
  • 33
  • 49

2 Answers2

1

I guess your database is MS SQL Server.

SQL Server stores time in HH:MI:SS format. Use TimeSpan in your model to store/get the data.

Here is another possible solution: How to save time only without the date using ASP.NET MVC 5 Data Annotation "DataType.Time?

Rahatur
  • 3,147
  • 3
  • 33
  • 49
  • 1
    Actually, SQL Server *Displays* time in `HH:MI:SS`, but it is stored as the number of ticks since midnight, Ticks being 100 nanosecond. – Zohar Peled Apr 04 '19 at 06:29
0
DateTime newintime = DateTime.Parse(Request["intime"].ToLongTimeString()); //change here
DateTime newouttime = DateTime.Parse(Request["out_time"].ToLongTimeString());// here also
model =  db.bookm.Where(x=>x.intime>= newintime && x.out_time <= newouttime ).First();

user ToLongTimeString();

patel vinay
  • 85
  • 1
  • 1
  • 8