Dear Wiki user, You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.
The "IsoFormattedDateAsDocId" page has been changed by DougShawhan. The comment on this change is: Had examples out of order. http://wiki.apache.org/couchdb/IsoFormattedDateAsDocId?action=diff&rev1=6&rev2=7 -------------------------------------------------- "map": "function(doc) {\n var dt = new Date(doc._id);\n emit(dt.getDate(), 1);\n}", "reduce": "function(keys, values, rereduce) {\n return sum(values)\n}" } - } - }}} - - Another advantage is using parseint() and datetime.substr() to cut out useful values for a return key: - - {{{#!javascript - function (doc) { - var datetime = doc._id; - var year = parseInt(datetime.substr(0, 4)); - var month = parseInt(datetime.substr(5, 2), 10); - var day = parseInt(datetime.substr(8, 2), 10); - var hour = parseInt(datetime.substr(11, 2), 10); - var minute = parseInt(datetime.substr(14, 2), 10); - emit([doc.widget, year, month, day, hour, minute], 1); } }}} @@ -46, +32 @@ ]} }}} + Another method is using parseint() and datetime.substr() to cut out useful values for a return key: + + {{{#!javascript + function (doc) { + var datetime = doc._id; + var year = parseInt(datetime.substr(0, 4)); + var month = parseInt(datetime.substr(5, 2), 10); + var day = parseInt(datetime.substr(8, 2), 10); + var hour = parseInt(datetime.substr(11, 2), 10); + var minute = parseInt(datetime.substr(14, 2), 10); + emit([doc.widget, year, month, day, hour, minute], 1); + } + }}} + + + If you have python views enabled, you can use the datetime module in the same way: {{{#!python
