cocoa touch - Compare dates from given array and two date ranges swift -


hi have problem scenario date comparison given date range scenario follows:

i have array containing data:

var filter1date = [string]()  filter1date[wed, 06 may 2015 03:44:19 gmt, wed, 06 may 2015 03:36:27 gmt, wed, 06 may 2015 02:56:51 gmt, wed, 06 may 2015 01:54:25 gmt, tue, 05 may 2015 19:17:18 gmt, wed, 06 may 2015 02:57:59 gmt, wed, 06 may 2015 02:07:38 gmt, wed, 06 may 2015 01:53:14 gmt, tue, 05 may 2015 14:30:10 gmt, tue, 05 may 2015 14:04:34 gmt] 

now have 2 dates gives from , to 2 dates example:

var fromdate = "dd-mm-yyyy" var todate = "dd-mm-yyyy" 

now want compare array of filter1date variable range fromdate , todate variable

from have data filter1date ranges in between these dates can me in this?

to compare 2 nsdates can use nsdate.compare() method. wrote extension nsdate handle this:

extension nsdate {     func isinrange(from: nsdate, to:nsdate) -> bool     {         if(self.compare(from) == nscomparisonresult.ordereddescending || self.compare(from) == nscomparisonresult.orderedsame)         {             if(self.compare(to) == nscomparisonresult.orderedascending || self.compare(to) == nscomparisonresult.orderedsame)             {                 // date in range                 return true             }         }         // date not in range         return false     } } 

you can use this:

var dates:[nsdate] = ... // dates array  var startdate:nsdate // start range date var enddate:nsdate // end range date  date in dates {    if(date.isinrange(startdate, to: enddate))    {       //date in range,    }    else    {       //date not in range    } } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

c# - Retrieve google contact -

javascript - How to insert selected radio button value into table cell -