Access97比较两个日期

时间:2018-11-21 13:36:58

标签: php sql date

我正在尝试将2个日期与一个SQL查询进行比较,

我的查询是这样

"SELECT table.toto
FROM table
WHERE 
table.date < $date"

$date是一个来自我的PHP代码的变量

在我的表中,我的日期格式如下:dd/mm/YYYY

不幸的是,它不能按预期方式工作,它仅返回一个结果(应该返回更多结果),其日期为:1312-09-15 00:00:00,但在数据库中,日期的格式类似于dd / mm / YYYY。

1 个答案:

答案 0 :(得分:0)

好吧,我找到了解决问题的方法。

我不知道为什么,但是我只是将“ $ date”格式设置为:"SELECT table.toto FROM table WHERE table.date < #date#" 并将其包装在这样的代码中的“#”之间:

 Query ref = mDatabaseReference.child("Messages")
            .child(MessageRecieverId).child(MessageSenderId).orderByChild("Seen").equalTo(false);
    ref.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            long count = 0;
            for(DataSnapshot ds : dataSnapshot.getChildren()) {
                count = dataSnapshot.getChildrenCount();

                MainData helper = new MainData(getApplicationContext()); //Change the name to your Helper Class name
                SQLiteDatabase db = helper.getWritableDatabase();
                String newId = "MyData";
                Cursor data = helper.getData();
                long newDatar = 0;
                long newDatat = 0;
                while(data.moveToNext()){
                    newId = data.getString(data.getColumnIndex("Data"));
                    newDatar = data.getInt(data.getColumnIndex("TotalMessagesRecieved"));
                    newDatat = data.getInt(data.getColumnIndex("TotalMessages"));
                }
                ContentValues contentValues = new ContentValues();
                contentValues.put(KEY_DATA, newId);
                contentValues.put(KEY_TOTAL_MESSAGES_RECIEVED, (newDatar+count));
                contentValues.put(KEY_TOTAL_MESSAGES, (newDatat+count));//Change the value of newData(which is actually your old value) by incrementing
                long returnVariable = db.update(TABLE_MAIN_DATA, contentValues, null, null);

                if(returnVariable == -1){
                    Toast.makeText(getApplication(),"Nope", Toast.LENGTH_LONG).show();
                    //-1 means there was an error updating the values
                }
                else{
                    Toast.makeText(getApplication(),"r", Toast.LENGTH_SHORT).show();
                }



            }
            Log.d("CMONNN", String.valueOf(count)); //Will print the number of seen messages
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {
            Log.d("CMONNN", databaseError.getMessage()); //Don't ignore errors!
        }
    });