Objective-C: How to check if date occurred between two dates? -


i searched question before , found:

if (([datetocompare compare:4hoursearlier] == nsorderedascending) && ([datetocompare compare:specifieddate] == nsordereddescending)) {     nslog(@"datetocompare between 4hoursearlier , specifieddate");     // } 

unfortunately, seems not work (the nslog never gets printed).

i have loop goes through array (which contains dates). need check if specified date within 4 hours of date. have (pseudocode):

specifieddate = date specify; datetocompare = current date gathered in loop; 4hoursearlier = 4 hours before specifieddate; 

how can check if specifieddate within 4 hours of datetocompare (a date gathered array/for loop)?

i think got comparisons wrong way around. exchange nsorderedascending , nsordereddescending in condition.

my memory aid is

[obj1 compare:obj2] == nsorderedascending  : obj1, obj2 ascending sequence [obj1 compare:obj2] == nsordereddescending : obj1, obj2 descending sequence 

therefore, check if datetocompare later in time fourhoursearlier, have use

if ([datetocompare compare:fourhoursearlier] == nsordereddescending) ... 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -