Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7433771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:43:30+00:00 2026-05-29T09:43:30+00:00

I know there are many NSDateFormatter questions on here, so if I duplicate, I’m

  • 0

I know there are many NSDateFormatter questions on here, so if I duplicate, I’m sorry. I just couldn’t find anything that was quite what Im asking.

From all the questions here on SO, I have come to the conclusion that -[NSDateFormatter dateFromString:] will always return NULL if your formatter object doesn’t have the correct date format. How do you get a date from a string if you don’t know the format? I’m trying to get a date from a UITextField.

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setLocale:[NSLocale currentLocale]];
[formatter setLenient:YES];
NSDate *tempDate = [formatter dateFromString:self.birthdayTxtfld.text];
self.currentCustomer.birthday = ([self.birthdayTxtfld.text isEqualToString:@""]) ? NULL : tempDate;
[formatter release];

tempDate is always NULL.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:43:31+00:00Added an answer on May 29, 2026 at 9:43 am

    I think your taking the wrong approach. I would on the other hand restrict and format the UITextField so the user has to enter the date in a specific format. Or just use a date picker. There are just way too may different inputs the user could give you.

    Or you can read through this: NSDate

    Another option is to create a list of accepted date formats:
    #define DATEFORMATS @[@"MM/dd/yyyy", @"MM/dd/yy",...
    Then Have a method that you pass the date string to and check if you can format it:

    + (NSDateFormatter*)getDateFormat:(NSString*)dateString {
    
        NSArray *dateFormats = DATEFORMATS;
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        NSDate *date = nil;
        for (NSString *dateFormat in dateFormats) {
            [formatter setDateFormat:dateFormat];
            date = [formatter dateFromString:dateString];
            if (date) {
                return formatter;
            }
        }
        return nil;
    }
    

    If you get nil its not a date or its in a format you don’t support. Otherwise you will have the correct format you need. You can switch this around to return the date instead of the format. I have it this way because I needed the format not the date for a project.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NOTE: I know there are many questions that talked about that but I'm still
I know that there are many Delphi database related questions available, but I'm considering
I know that there are many different questions about this sort of topic on
I know there are many questions asking for this, but I have tried quite
I know there are many dict to list questions on here but I can't
I know there are many other posts on here with similar questions, but I
I know there are many questions similar but any of them didn't help. in
I know there are already many questions like mine but I found no answer
Firstly I know that there are many question and solutions to correct thread marshalling
I know there are many questions about jQuery + Back button issues, but it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.