## Need help sorting data on date

**This question already has answers here**:

In javascript, there is a method known as `.sort()`

in Array which can be used for sorting. This is how it works.

- If compareFunction(a, b) is less than 0, sort a to an index lower than b (i.e. a comes first).
- If compareFunction(a, b) returns 0, leave a and b unchanged with respect to each other, but sorted with respect to all different elements. Note: the ECMAScript standard does not guarantee this behaviour, thus, not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this.
- If compareFunction(a, b) is greater than 0, sort b to an index lower than a (i.e. b comes first).
- compareFunction(a, b) must always return the same value when given a specific pair of elements a and b as its two arguments. If inconsistent results are returned, then the sort order is undefined.

So in our case, we need to sort it in descending order. i.e objects with less priority must come at the top. For that, we need to return a number which is less than 0. Which can be done if we subtract the priority of `b`

by priority of `a`

.

In the code:

const items = [{ subject: 'something', email: 'someone@gmail.com', name: 'Bert', priority: '2' }, { subject: 'something else', email: 'someoneelse@gmail.com', name: 'Betty', priority: '4' }, { subject: 'another thing', email: 'anotherone@gmail.com', name: 'Joanne', priority: '1' }]; const sorted = items.sort((a,b) => b.priority - a.priority); console.log(sorted);

**How to sort by date in Excel: chronologically, by month, auto sort,** If it says any other format, then chances are that Excel doesn't recognize it as a date. You can also select the data that needs to be sorted and� Sorting data helps you quickly visualize and understand your data better, organize and find the data that you want, and ultimately make more effective decisions. You can sort data by text (A to Z or Z to A), numbers (smallest to largest or largest to smallest), and dates and times (oldest to newest and newest to oldest) in one or more columns.

var f =[{ subject: 'something', email: 'someone@gmail.com', name: 'Bert', priority: '2' }, { subject: 'something else', email: 'someoneelse@gmail.com', name: 'Betty', priority: '4' }, { subject: 'another thing', email: 'anotherone@gmail.com', name: 'Joanne', priority: '1' }]; f.sort((a,b) => +b.priority - +a.priority) console.log(f)

**How to Sort by Date in Microsoft Excel,** How to sort by date in Microsoft excel. 272,914 Recommended for you Excel 2007 Duration: 1:26
Posted: Feb 2, 2016 I need to sort a data frame by date in R. The dates are all in the form of "dd/mm/yyyy". The dates are in the 3rd column. The column header is V3. I have seen how to sort a data frame by column and I have seen how to convert the string into a date value. I can't combine the two in order to sort the data frame by date.

I wrote a generic function to do the sort by a property name as well as ascending and descending order feature.

function sortDataByPropName(data, property, order) { if(order === 'asc'){ data.sort((a, b) => a[property] - b[property]) } else { data.sort((a, b) => b[property] - a[property]) } return data; }

In your case, you can simply call this function like `sortDataByPropName(data, 'priority')`

or if you want change sort order then simply pass third argument like `asc`

default is `desc`

.

**Sorting Dates and Times (Microsoft Excel),** Want to sort by date in Google Sheets? Here are two simple ways to sort the data by date in Google Sheets and possible reasons (& solution) it may not work. Need Help Sorting Data, Any Help Appreciated. I'm hoping someone can help me out with creating an workbook that will save me a ton of time. I have a set of data that is based on consecutive serial numbers (300,000 to be exact).

Use `sort`

& convert the value of `priority`

from string to number using `parseInt`

.

let data = [{ subject: 'something', email: 'someone@gmail.com', name: 'Bert', priority: '2' }, { subject: 'something else', email: 'someoneelse@gmail.com', name: 'Betty', priority: '4' }, { subject: 'another thing', email: 'anotherone@gmail.com', name: 'Joanne', priority: '1' } ]; let sortedDt = data.sort(function(a, b) { return parseInt(b.priority, 10) - parseInt(a.priority, 10) }); console.log(sortedDt)

**How to sort by date in Microsoft excel,** kenbutler April 18, 2018, 3:30pm #5 the advantage to lubridate is that sorting dates with arrange will just work. Otherwise, you need to make sure your dates are in something like yyyy-mm-dd order (perhaps yyyy-mm in your case) as text so that they will sort into the right order.

**How to Sort by Date in Google Sheets (using Formula ,** I'm hoping someone can help me out with creating an workbook that will save me a ton of time. I have a set of data that is based on consecutive serial numbers (300,000 to be exact). I have provided two spreadsheets below, the first is an example of what the data looks like, and the second would be what I would want the data to look like.

Of course, there’s a good chance that you’re using your spreadsheet for numerical data. The sorting process is exactly the same for numbers. On the second sheet of the example workbook, we have a long list of stores and their associated revenue. Let’s sort by revenue to see which stores are doing best.

To find the birth date you need, you must still search the entire dataset one item at a time. Consequently, sorting must focus on a particular need. Yes, you needed the employee database sorted by department at one point and by last name at another time, but now you need it sorted by birth date in order to use the dataset effectively.

##### Comments

- ...and we need some more answers about
`sort()`

, so, please, join - ...and the Oscar goes to the most long-winded orator, posting his identical solution 8 minutes after first answer
- How much research effort is expected of Stack Overflow users?
- this works. Do you know perhaps how to apply a secondary filter?