【问题标题】:How can I get my ajax request date format to match my database date format?如何让我的 ajax 请求日期格式与我的数据库日期格式相匹配?
【发布时间】:2014-05-31 17:26:36
【问题描述】:

我一直在尝试在这样的 linq 查询中使用日期:

 public ActionResult GetSchedule(string selectedDate)
    {

  DateTime daySearch = Convert.ToDateTime(selectedDate);
        viewModel.Assignments = from a in db.Assignments where a.teacherId == intTeacherId select a;

问题是我的数据库中的日期格式看起来我的数据库日期看起来像这样

“2014-05-26 00:00:00.0000000”和我的 ajax 调用日期如下所示...5/26/2014:12:00:00 AM。

我尝试了一个看起来像……的请求

 var allTeacherSchecules = from x in db.Assignments where x.teacherId == intTeacherId select x;

 viewModel.Assignments = from ss in allTeacherSchecules where allTeacherSchecules Contains(selectedDate) select ss; 

...这样我就不必担心特定的匹配,但“包含”在这里不起作用。
如何让我的 ajax 请求日期格式与我的数据库日期格式相匹配?

【问题讨论】:

    标签: asp.net sql ajax linq


    【解决方案1】:

    我认为您以错误的方式解决问题。您的查询应该合并为一个,以利用 linq 和数据库的功能。尝试重写

    var allTeacherSchecules = from x in db.Assignments where x.teacherId == intTeacherId select x;
    
     viewModel.Assignments = from ss in allTeacherSchecules where allTeacherSchecules Contains(selectedDate) select ss; 
    

    类似

    viewModel.Assignments = (from x in db.Assignments 
    where x.teacherId equals intTeacherId 
    and x.assignmentDate equals selectedDate
    select x).ToList();
    

    【讨论】:

      猜你喜欢
      • 2020-02-19
      • 2012-10-03
      • 2013-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-24
      相关资源
      最近更新 更多