Swift 2.3 Closest Hour (Greater or Equal) from Current Date

I have to determine H and H+3 where H is >= to nearest Hour. Let me show you some examples : if today's hour is 0h00 -> H = 0h and H+3 = 3h if today's hour is 0h01 -> H = 1h and H+3 = 3h if today's hour is 21h00 -> H = 21h and H+3 = 0h if toda

Set NSDates days to the same value

I want to compare 2 specific days, but, i want to compare month and year, not days. For example, i got one date something like 2016-08-16, and other date like 2016-08-10, i need to compare dates and got equality, because their month are equal. Theref

NSDate's date method returns bad weather

This question already has an answer here: Getting date from [NSDate date] off by a few hours 3 answers Simple question, annoying problem. I have a date picker with which I select a time (say 11 AM). Then a button that's connected to a method that pri

How to give age validation in iOS?

Have created below function for age validation, but its not giving me proper out. Anyone know how to do it ? Some other code tried but it was depricated. My app target is iOS 7 and later. Selected Date - 13/03/1990 Output You live since -68 years and

How to convert a short date formatted string to NSDate

I have a string containing date in a short date format, which i would like to convert to NSDate. What I tried is as follows NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"MM/dd/yyyy h:mm a"]; NSDate *da

Compare the Date object?

I have this date object from Parse, "2015-07-24 20:36:38 +0000" and I would like to compare it to today's date to see how much time has passed since the date on the date object. Any ideas how to do this? I have this method I use to get the hour

how to convert from Uk time to Mexico time zone

I am having an array in that date are in UK time zone. I want to convert that UK time zone to below country time. I am having two radio button Mexico (UTC-6) India - IST (UTC+5.30) when i click Mexico (UTC-6) radio button my array date are convert to

NSDateFormatter problem with date format in iOS 8

I have an NSDateFormatter which I use to format an NSDate into a string. The following format does not work: ddMMyyyy_hhmmss_SSS. When I try to format an NSDate I get the following output: 18092014_08:49:03,638, which has a colon and a comma I didn't

The date can not be compared

I want to check if user selected date is the same as the current date or not. I am using this code. I can check if the selected date is in the past or future, but I can't detect if it is the same, because when I log both dates it is in this format. I

Comparing the predicate dates of the master data

Im trying to fetch all the objects in an entity matching a user selectedDate (it's an NSDate). The Core Data code is fine but my predicate keeps returning 0 results, the dates are the same in the database as the user is selecting. How should the sele

NSDate return time / day / week

Snaps in Instagram program, date shown as (for example) 2 hours ago/3 days ago/ 1 week ago.. I have "2013-03-20 16:02:48".. how can I get string "2 days ago"?Consider using NSCalendar and NSDateComponents to calculate differences and a

Get NSDate from seconds in ObjC

This question already has an answer here: NSTimeInterval to NSDate 7 answers I have got seconds as 54000. How can i get the time as 3:00:00 PM ? Any dateformatter's i can use to get it ? ThanksAssuming given seconds are in local time zone and you wan

Validation of date and month

i have a current date using NSDate which is ma start date....and i add 4 more days to the current date where i get ma endDate.. NSString *StrtDate= [dateFormatter stringFromDate:[NSDate date]]; int daysToAdd = 4; NSDate *newDate1 = [[NSDate date] dat

format date according to my requirement

I want to make date by date formatter 2012-07-12 but it display like 2012-07-11 My code: NString * today_selected=[NSString stringWithFormat:@"%d%@%d%@%d",year_for_activated,@"-",month_for_activated,@"-",taged]; NSDateFormatt

Date error when formatting in iphone?

Hi I am trying to format date which I m getting from server. I have tryed like this NSString *dateStr [email protected]"2012-5-21"; // Convert string to date object NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"

Minimum and maximum date in UIDatePicker

I want to get the minimum and maximum date from a date picker, but minimum date should be "- 18" of the current date and the maximum date should be "- 100" of current date. Suppose current year is 2018 then I want minimum date 2000 and

NSString format to NSDate

i take the user date from facebook , it look like "birthday_date" = "03/04/1987" i wrote this code NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@"dd/MM/YYYY"]; NS

How to check NSDate against a TAPKU calendar date

I am using core data to store objects for my project.There is a date field in the object .I want to check against the clicked date of the Tapku calendar component for iphone. The date on my object is in the format 2011-01-10 and it is a localized dat

NSDate returns an incorrect date on the first day of the month

My app used [NSDate date ] function to get current date. Its work fine other days except 1st of every month during AM. i.e Follow Following steps : Set the system date as 01 - June - 2011 & time between 00.00 midnight to 5.59 AM. Use following code :

Why would NSDate be inconsistent between devices?

The following method attempts to calculate the number of days in a year of an NSHebrew calendar object, given a hebrew year. For some reason, I'm getting inconsistent results across devices. The test case was the date of May 25, 1996. One device was

Help with date formats

What's the correct format to parse this string: "Mon, 14 Mar 2011 15:36:00 GMT" into a NSDate using NSDateFormatter? NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@"EEE, d MMM yy

How to use NSDate formatter with an array of dates?

I'm trying to generate an array of 30 days from the current date and put them into an array formatted correctly. I currently have a working generater to get 30 days from the current date and put it into an array but I don't know how to use NSDate for

How can I get the day of the week with Cocoa Touch?

How do I get the day of the week as a string in Objective-C? NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@"EEEE"]; NSLog(@"%@", [dateFormatter stringFromDate:[NSDate date]

NSDate initialization problem on the iPhone

I am trying to do some basic operations with Dates on the iPhone. I want to take a string like "2010-02-19" and turn it into a string like "Friday, Feb 19." The strings I will be receiving will always be in 2010-02-19. Right now, I am

How to compare two dates?

I have three dates: (1) previousDate (2) currentDate (3) nextDate, I want to check whether currentDate is later then previous date and earlier than nextDate. How do I do that? NSDateFormatter *df= [[NSDateFormatter alloc] init]; [df setDateFormat:@"y

Do I need to keep the date of a UIDatePicker modal view?

I'm getting crashes from my UIDatePicker view and I think it's because I'm not retaining the pickers selected date. Can anyone tell me if this could be correct? I have a modal view for selecting a toDate and a fromDate range. These values are passed