在mysql中比较两个日期

时间:2018-09-12 06:56:12

标签: php mysql

酒店入住和退房时间为

表格数据

   check in                   check out                room name
2018-09-17 11:00:00           2018-09-19 11:00:00      room 1
2018-09-18 11:00:00           2018-09-19 11:00:00      room 2
  

注意:标准入住和退房时间:上午11:00

如果我尝试约会from 2018-09-17 11:00:00 to 2018-09-18 11:00:00,那么output for that date total booked should be 1. 1号房间已被预订,2号房间应该是免费的。

我的查询

SELECT * FROM transcationmaster WHERE checkin >= STR_TO_DATE('2018-09-17 11:00:00', '%Y-%m-%d %H:%i:%s') and  checkout  <= STR_TO_DATE('2018-09-18 11:00:00', '%Y-%m-%d %H:%i:%s') 

如何在mysql中做到这一点?

预先感谢

1 个答案:

答案 0 :(得分:3)

这只是重叠范围问题。要查找与您自己的日期范围重叠的记录,请尝试以下查询:

#include <iostream>
#include <stdio.h>
#include <Eigen/Core>

using namespace Eigen;

template<class ArgType, class RowIndexType, class ColIndexType>
class indexing_functor {
  const ArgType &m_arg;
  const RowIndexType &m_rowIndices;
  const ColIndexType &m_colIndices;
public:
  typedef Matrix<typename ArgType::Scalar,
                 RowIndexType::SizeAtCompileTime,
                 ColIndexType::SizeAtCompileTime,
                 ArgType::Flags&RowMajorBit?RowMajor:ColMajor,
                 RowIndexType::MaxSizeAtCompileTime,
                 ColIndexType::MaxSizeAtCompileTime> MatrixType;
  indexing_functor(const ArgType& arg, const RowIndexType& row_indices, const ColIndexType& col_indices)
    : m_arg(arg), m_rowIndices(row_indices), m_colIndices(col_indices)
  {}
  const typename ArgType::Scalar& operator() (Index row, Index col) const {
    return m_arg(m_rowIndices[row], m_colIndices[col]);
  }
};

template <class ArgType, class RowIndexType, class ColIndexType>
CwiseNullaryOp<indexing_functor<ArgType,RowIndexType,ColIndexType>, typename indexing_functor<ArgType,RowIndexType,ColIndexType>::MatrixType>
indexing(const Eigen::MatrixBase<ArgType>& arg, const RowIndexType& row_indices, const ColIndexType& col_indices)
{
  typedef indexing_functor<ArgType,RowIndexType,ColIndexType> Func;
  typedef typename Func::MatrixType MatrixType;
  return MatrixType::NullaryExpr(row_indices.size(), col_indices.size(), Func(arg.derived(), row_indices, col_indices));
}

enter image description here

Demo