Languages

Menu
Sites
Language
Comparing "datetime-local" type

I have stored the date and time in datetime-local format in indexeddb . Now when I am reading the values from the database, I need dates and time which are later than current datetime so I am using the following code for it - 

var transaction = db.transaction(["trips"],"readonly");
    var store = transaction.objectStore("trips");
    var myindex = store.index("startDate");
   
        range = IDBKeyRange.lowerBound("tizen.time.getCurrentDateTime()");

    myindex.openCursor(range).onsuccess = function(e) {
        var cursor = e.target.result;
        
        if(cursor) {
            var tableRow = document.createElement('tr');
            tableRow.innerHTML =   '<td>' + cursor.value.destination + '</td>'
                                 + '<td>' + cursor.value.startDate + '</td>'
                                 + '<td>' + cursor.value.endDate + '</td>'
                                 + '<td>' + cursor.value.notes + '</td>';
                              
            tableEntry.appendChild(tableRow);  

            cursor.continue();
          } else {
            console.log('Entries all displayed.');    
          }
        }

 

I am entering these values in a table so basically I need to know what should be given as parameter to the lowerbound statement instead of "tizen.time.getCurrentDateTime()"

range = IDBKeyRange.lowerBound("tizen.time.getCurrentDateTime()");

Edited by: Siddharth Bhardwaj on 25 Mar, 2015

Responses

3 Replies
daniel kim

Hi,

If date&time operation is not available in Indexed Database, I think that you need to check data of each cursor manually using this api. but it can be a overhead.

    boolean laterThan(TZDate other);

https://developer.tizen.org/documentation/articles/time-api-guide#formats

Regards,

Siddharth Bhardwaj

I tried that too.

my date and time is stored as 'date-time local' form input type so I am getting it back here as 'cursor.value.startDate'. How do I compare it with 'tizen.time.getCurrentDateTime()' which is a TZDate object? 

I tried something like -

if((cursor.value.startDate).laterThan(tizen.time.getCurrentDateTime())){}

it says 'Uncaught TypeError: undefined is not a function'.

daniel kim

Hi,

It seem that you need to convert 'date-time local' to date format before storing data to IndexedDB.

Please refer to below links.

  http://stackoverflow.com/questions/24691501/how-to-convert-datetime-local-to-datetime-while-storing-and-retrieving-from-data

  http://stackoverflow.com/questions/476105/how-can-i-convert-string-to-datetime-with-format-specification-in-javascript

 

Regards,