我希望能够通过检查sqlalchemy
列是否高于某一日期(即现在的1天)来过滤datetime
查询。
任何想法这样做的正确语法是什么?
注意:
1 .sqlalchemy查询看起来应该是这样的:
one_day_interval_before = ?
result = session.query(People).filter(People.registered_at>= one_day_interval_before).all()
答案 0 :(得分:4)
对于Python中的时间间隔,请使用datetime.timedelta
。前一天将是:
from datetime import datetime, timedelta
one_day_interval_before = datetime.now() - timedelta(days=1)
答案 1 :(得分:1)
datetime.datetime.strftime(datetime.datetime.now()-datetime.timedelta(1),'%Y-%m-%d')
答案 2 :(得分:0)
你也可以使用包含大多数sql函数的private BluetoothAdapter.LeScanCallback mLeScanCallback;
{
mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
Data = scanRecord;
// Convert Hex to String
int temp, digit1,digit0;
stringData="";
for (int i = 1; i < Data.length; i++)
{
temp = Data[i] & 0xff;
digit1 = temp >> 0x04;
digit0 = temp & 0x0f;
stringData += String.valueOf(digit1) + String.valueOf(digit0);
}
RSSI = rssi;
runOnUiThread(new Runnable() {
@Override
public void run() {
mLeDeviceListAdapter.addDevice(device);
mLeDeviceListAdapter.notifyDataSetChanged();
}
});
}
};
}
func