87005

How to sort string date angularjs

Question:

How sort string date format 24.01.2017 ( descending ) I tried with Date.parse('24.01.2017'); -> but incorrect format

How sort date like this? in controller or view Thanks

Getting data from api want sort by _title <a href="https://i.stack.imgur.com/TGSXs.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/TGSXs.png" data-original="https://i.stack.imgur.com/TGSXs.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

Answer1:

Try the orderBy filter with a custom comparing function:

JS:

$scope.entries = [ {date: '05.02.2001'}, {date: '01.20.1930'}, {date: '03.20.2020'} ] $scope.compareDates = function(date1, date2) { console.log(date1) var split1 = date1.value.split('.'); var split2 = date2.value.split('.'); var date1compare = split1[2] + split1[1] + split1[0]; var date2compare = split2[2] + split2[1] + split2[0]; return (date1compare > date2compare ? 1 : -1) }

HTML:

<div ng-repeat="entry in entries | orderBy:'date':false:compareDates"> {{entry.date}} </div>

Plunker: <a href="https://plnkr.co/edit/LETAFDoD5fub63tKI5Ne?p=preview" rel="nofollow">https://plnkr.co/edit/LETAFDoD5fub63tKI5Ne?p=preview</a>

Recommend

  • Render a section of an image to a Bitmap C# Winforms
  • Multiplying two lists in prolog
  • Find a object key from a HashMap
  • How to get number of specific rows from a different table in a subquery
  • Why are there differences in psych::principal between “Varimax” and “varimax”?
  • Timezone lookup
  • synchronous AJAX post from unload event: how to ensure user sees most up-to-date information from DB
  • TypeScript 2.0 throws errors from excluded files?
  • Sending signal to thread from annother non-process and logging stack not happening
  • Glassfish/Wildfly not failing if @Resource cannot be resolved?
  • Individual Preferences for each item in a ListView?
  • overhead of reserving address space using mmap
  • How do i convert a List to List in c#
  • Python: include entries of a dictionary in the local namespace of a function
  • EventLog logs in Application, even though set to another log
  • Have anyone succeeded in ThinApp'ing Visual Studio?
  • In explicit LINQ-to-SQL (C#) does order matter?
  • git push origin master denied to user X where x is NOT the user in the local git config
  • Swift string variables localization
  • How to use ResourceDictionary in Windows Phone class library project
  • Sum data table columns using linq
  • Count from each distinct date, fill in missing dates with zero
  • How can I get the choice “H2” back in the H2 consol?
  • Updating Dojo provide
  • How do I shift the decimal place in Python?
  • Sort List of Strings By Version
  • Is it possible to access block's scope in method?
  • Django: Count of Group Elements
  • Spring security and special characters
  • Bug in WPF DataGrid
  • Redux, normalised entities and lodash merge
  • bootstrap to use multiple ng-app
  • retrieve vertices with no linked edge in arangodb
  • how does django model after text[] in postgresql [duplicate]
  • embed rChart in Markdown
  • Linking SubReports Without LinkChild/LinkMaster
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app
  • Python/Django TangoWithDjango Models and Databases