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 778405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:45:30+00:00 2026-05-14T19:45:30+00:00

I have the data as customerFromDate 01 Apr 2010 and customerToDate 30 Apr 2010

  • 0

I have the data as customerFromDate ” 01 Apr 2010 ” and customerToDate ” 30 Apr 2010 ” which is a string.

I want to convert that format into the string “yyyy-MM-dd”, but when doing so I got null values.
Please see the following code which I had tried.

printf("\n customerFromDate %s",[customerStatementObj.customerFromDate UTF8String]);
printf("\n customerToDate %s",[customerStatementObj.customerToDate UTF8String]);
/*
 prints as the following 
 customerFromDate 01 Apr 2010
 customerToDate 30 Apr 2010
 */

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSDate *fromDate=[[NSDate alloc]init];
fromDate = [dateFormatter dateFromString:customerStatementObj.customerFromDate];
printf("\n fromDate: %s",[fromDate.description UTF8String]);
NSString *fromDateString=[dateFormatter stringFromDate:fromDate];
printf("\n fromDateString: %s",[fromDateString UTF8String]);    
[dateFormatter release];

NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc]init];
[dateFormatter1 setDateFormat:@"yyyy-MM-dd"];
NSDate *toDate=[[NSDate alloc]init];
toDate = [dateFormatter1 dateFromString:customerStatementObj.customerToDate];
printf("\n toDate: %s",[toDate.description UTF8String]);
NSString *toDateString=[dateFormatter1 stringFromDate:toDate];
printf("\n toDateString: %s",[toDateString UTF8String]);            
[dateFormatter1 release];

Thank you,
Madan Mohan.

  • 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-14T19:45:31+00:00Added an answer on May 14, 2026 at 7:45 pm

    Several notes:

    You need two different NSDateFormatters. One that specifies the input date format, and one that specifies the output date format.

        NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
        [inputFormatter setDateFormat:@"dd MMM yyyy"];
        NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
        [outputFormatter setDateFormat:@"yyyy-MM-dd"];
    

    You can reuse these formatters for both your fromDate and your toDate.

    Secondly, dateFromString: returns an allocated, autoreleased NSDate object. You are leaking the ones you manually allocate.

    #import <Cocoa/Cocoa.h>
    
    int main (int argc, char const *argv[])
    {
        NSAutoreleasePool *pool = [NSAutoreleasePool new];
    
        NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
        [inputFormatter setDateFormat:@"dd MMM yyyy"];
        NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
        [outputFormatter setDateFormat:@"yyyy-MM-dd"];
    
        NSDate *fromDate = [inputFormatter dateFromString:@"01 Apr 2010"];
        NSDate *toDate = [inputFormatter dateFromString:@"30 Apr 2010"];
    
        printf("\n fromDate: %s",[fromDate.description UTF8String]);
        NSString *fromDateString=[outputFormatter stringFromDate:fromDate];
        printf("\n fromDateString: %s",[fromDateString UTF8String]);
    
        printf("\n toDate: %s",[toDate.description UTF8String]);
        NSString *toDateString=[outputFormatter stringFromDate:toDate];
        printf("\n toDateString: %s",[toDateString UTF8String]);
    
        [inputFormatter release];
        [outputFormatter release];
    
        [pool drain];
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have data from an Excel spreadsheet that I want to import into a
I have data that is mostly centered in a small range (1-10) but there
I have data on a server which stores name and images. I want to
I have data that I would ideally want to represent as so: LinkedList<T>[] However,
I have data in a particular format and I want to store them through
I have data with amount of 2 millions needed to insert into postgresql. But
I have data files in the .RDa format under the data sub directory. But,
i have data-grid in my application and i want to customize my data-grid so
I have data from travel diaries which has been read in from a csv
I have data-segment attribute in my body tag that is changed by a slider.

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.