-4

Possible Duplicate:
How to Check if an NSDate occurs between two other NSDates

In my application i have got the time in string like this,

starttime(string) : 10:00 AM

endtime(string) : 12:22 PM

My current time is 11.55 AM

How can i check my current time is between starttime and endtime?

Community
  • 1
  • 1
Anki
  • 589
  • 2
  • 13
  • 22
  • This will probably be the easiest. http://stackoverflow.com/questions/9807370/how-to-check-if-date-from-date-picker-is-between-two-other-dates-objective-c – mlstudent Jan 23 '13 at 08:29

2 Answers2

0

Use this way :

First convert your string to NSDate using NSDateFormatter.

Then directly compare those two dates with currentDate which is always [NSDate date].

You may use these two instance method of NSDate.

isGreaterThan: and isLessThan:

Or,

if (! (([currentDate compare:startDate]==NSOrderedAscending) && ([currentDate compare:endDate]==NSOrderedDescending)){
    NSLog(@"Valid date");
}
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
-1

First try to remove AM and PM

Like its PM then add +12 in that time frame.

Then check weather the current time's digits which is before ":" is greater then start time and less then end time.. and if it is return true then you can check for the digites after ":".

j0k
  • 22,600
  • 28
  • 79
  • 90
Krupall
  • 379
  • 3
  • 7