• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 562
  • Last Modified:

how to check if the time within the specific range using xcode for iphone

how i can check if the time is with in the  specific range using xcode for example if i have time = 4:00PM

i need         if condition if(time is between 1:00 PM and 5:00 PM)
                           {
                                   true
                            }
                  else
                            {
                                  false
                            }


best regards
0
deniro1974
Asked:
deniro1974
  • 2
  • 2
1 Solution
 
SpeedyApocalypseCommented:
Is 4:00PM stored as a string, NSDate object, etc?
0
 
pgnatyukCommented:
If the time is in hours, so compare three integer values like:
if (x >= a && x <= b)
{
}
If you are talking about NSDate objects, you can use NSCalendar and NSDateComponents to get the hours from the NSDate objects.
You can compare three NSDate objects and this is probably the simplest way:
if (([theDate compare:fromDate] != NSOrderedAscending) && ([theDate compare:toDate] != NSOrderedDescending))
{
  // do something
}


0
 
pgnatyukCommented:
Take a look also here - timeIntervalSinceReferenceDate:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html
You can convert the NSDate objects to NSTimeInterval and compare them as three float values.
0
 
deniro1974Author Commented:
dear speedy,

i want it to be NSdate.

Best regards
0
 
deniro1974Author Commented:
it's not the solution i need but it was helpful
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now