1

I'm querying firebase based on the dates. I find my query, but it doesn't look like firebase. The order of this is important to me. another picture link : firebase

 -LP6nkhewJCIGplnE6L4
adSoyad: 
"RUKIYE POLAT"
tarih: 
"18/10/2018,18:33:02"
-LP7EBqo6pabsweqH-4G
adSoyad: 
"RUKIYE POLAT"
tarih: 
"18/10/2018,20:32:56"
-LPBblB72HizL1LaJDIp
adSoyad: 
"RUKIYE POLAT"
tarih: 
"19/10/2018,16:58:45"
-LPCNo2DoDkArJJUQMCp
adSoyad: 
"RUKIYE POLAT"
tarih: 
"19/10/2018,20:33:01"
-LPF-MEziEXaoaNezNHQ
adSoyad: 
"RUKIYE POLAT"
tarih: 
"20/10/2018,8:45:03"
-LPGfoeIVNGq1MRmOEbY
adSoyad: 
"RUKIYE POLAT"
tarih: 
"20/10/2018,16:34:34"
-LPGfpCRniADm6sgGWyy
adSoyad: 
"RUKIYE POLAT"
tarih: 
"20/10/2018,16:34:34"
-LPK8Puua1kLv5eV7NOF
adSoyad: 
"RUKIYE POLAT"
tarih: 
"21/10/2018,8:42:44"
-LPLqoKyV_YiaMqKozxb
adSoyad: 
"RUKIYE POLAT"
tarih: 
"21/10/2018,16:40:42"
-LPLqosW54-5q8hUfNoK
adSoyad: 
"RUKIYE POLAT"
tarih: 
"21/10/2018,16:40:43"

sample, in Firebase Date: 20/10 / 2018,8: 32 there is another child under Date: 20/10 / 2018,16: 39

I also want to come like in this order. According to the time from the database ie in the order of the list as in the firebase.But Firstly,is coming

Date: 20/10 / 2018,16: 39
Date: 20/10 / 2018,8: 32 

But I want to as listed above first
Date: 20/10 / 2018,8: 32 Date: 20/10 / 2018,16: 39 another picture link :https://i.hizliresim.com/j691AL.jpg application

There are a lot of data in the database, so I can't fix it.

DatabaseReference dbGelenler = db.getReference(kimlik+"/"+cekilensifre+"/"+cekilenisim);

Query query = dbGelenler.orderByChild("tarih").startAt(birincitarih).endAt(birincitarih + "\uf8ff");
        query.addListenerForSingleValueEvent(new ValueEventListener() {
    public void onDataChange(DataSnapshot dataSnapshot) {

        List<String> isimler = new ArrayList<String>();
        for (DataSnapshot anahtar : dataSnapshot.getChildren()) {
            String isim = anahtar.getValue(ornekogrencigetir.class).getAdSoyad();
            String tarih = anahtar.getValue(ornekogrencigetir.class).getTarih();
            HashMap<String, String> user = new HashMap<>();

            if (isimler.indexOf(isim) == -1) {
                user.put("hashdurum", "Giriş");
                String[] seperated;
                seperated = tarih.split(",");
                user.put("hashtarih", seperated[0]);
                user.put("hashsaat", seperated[1]);
            } else {
                user.put("hashdurum", "Çıkış");
                String[] seperated1;
                seperated1 = tarih.split(",");
                user.put("hashtarih", seperated1[0]);
                user.put("hashsaat", seperated1[1]);
            }
            isimler.add(isim);
            veriler.add(user);

Why doesn't the query take a sequential manner? How can I fix this?

Edit:Error Solved:

The query information is sorted by time. Some times in my database does not contain 0 in front. These are the hours until 10 o'clock in the morning after 12 o'clock. For example, a.m 9. Therefore, when comparing the firebase clock, refer to the next one. Example of the situation 9:12:15 to 15:24:54 the situation he compares here is 91 and 15, so he takes 15: 24: 54 first and then gets 9:12:15.

Fırat
  • 35
  • 6
  • your links on hizliresim not works. 403 Forbidden. – Vadim Eksler Oct 22 '18 at 05:37
  • How I add picture with links – Fırat Oct 22 '18 at 11:21
  • It's better to include in your question the image without the link; in this way it'll be always available. – A. Wolf Oct 22 '18 at 11:49
  • Also, don't take screenshot of your code! Paste it in the question, it'll be easier to help you (and for you to find someone who answers) – A. Wolf Oct 22 '18 at 11:54
  • 1
    If you have problem simply paste it in the question, I'll format it a proper way. – A. Wolf Oct 22 '18 at 11:55
  • I will paste my code but when I add e picture it gives You need at least 10 reputation to post images error – Fırat Oct 22 '18 at 11:58
  • You've included a picture of the JSON tree in your question. Please replace that with the actual JSON as text, which you can easily get by clicking the Export JSON link in [your Firebase Database console](https://console.firebase.google.com/project/_/database/data/). Having the JSON as text makes it searchable, allows us to easily use it to test with your actual data and use it in our answer and in general is just a Good Thing to do. – Frank van Puffelen Oct 22 '18 at 14:13
  • You right but, Database include secret information – Fırat Oct 22 '18 at 14:14

1 Answers1

1

You store the date/time in your database in a string value, in the format dd/MM/yyyy hh:mm:ss. Strings in Firebase are lexicographically ordered, and unfortunately in the date format you use, the lexicographical order and the chronological order of the values are different.

The solution is to store the date/time value in a format that does allow it to be sorted in the way you want. The two most common ways are to store them as a timestamp (a numeric value that is the number of milliseconds since a specific date), or in a sortable string format (typically 2018-10-20T16:34:34).

For more on this, see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807