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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:43:29+00:00 2026-06-17T00:43:29+00:00

I’m developing an app which displays start date and end date, but I’m having

  • 0

I’m developing an app which displays start date and end date, but I’m having an issue with date displayed on textfield

everything works fine here: screenshot

but when I turn to December 30 2012 in output you can read that says 2012 (Hardcoded) but in textfield it writes 2013 (formatted):

screenshot

happens the same thing if I try using “All day” option:

screenshot

gonna share my app code as well for making things easier

#import "StartEndEventVC.h"
#import "visitVC.h"
#import "Functions.h"



@interface StartEndEventVC ()
{
    NSDate                  *date;
    NSDateFormatter         *df;
    NSString                *selectedCell;
}

@property (nonatomic, strong) Functions *funciones;
@end


@implementation StartEndEventVC

@synthesize funciones       = _funciones;
@synthesize datePicker      = _datePicker,
            SwitchDate      = _SwitchDate,
            fecFinDateSE    = _fecFinDateSE,
            fecInicioDateSE = _fecInicioDateSE;


#pragma mark *** Common methods ***
- (void)viewDidLoad
{
    [super viewDidLoad];

    //Datepicker initial settings
    self.datePicker.timeZone = [NSTimeZone localTimeZone];
    self.datePicker.locale   = [NSLocale currentLocale];
    self.datePicker.calendar = [NSCalendar currentCalendar];

    //Date format initial settings
     df             = [NSDateFormatter new];
    [df setDateFormat:@"EE, dd MMM YYYY HH:mm a"];
    [df setTimeZone:[NSTimeZone localTimeZone]];

    //initial cell to interact with datepicker
    selectedCell    = @"startDate";


    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"back"
                                                                             style:UIBarButtonItemStyleBordered
                                                                            target:self
                                                                           action:@selector(didBack:)];
}


-(void)estableceFechaCamposTexto{

    self.fecInicioDateSE        = [[NSDate alloc]init];
    self.fecFinDateSE           = [[NSDate alloc]init];

    self.fecInicioDateSE        = [NSDate date];
    self.fecFinDateSE           = [self.fecInicioDateSE dateByAddingTimeInterval:60*60];


    self.startDateLabel.text    = [df stringFromDate:self.fecInicioDateSE];
    self.endDateLabel.text      = [df stringFromDate:self.fecFinDateSE];
}


-(void)viewDidAppear:(BOOL)animated{
    if ((self.fecInicioDateSE == nil) || (self.fecFinDateSE == nil)) [self estableceFechaCamposTexto];

        self.startDateLabel.text    = [df stringFromDate:self.fecInicioDateSE];
        self.endDateLabel.text      = [df stringFromDate:self.fecFinDateSE];
}




-(Functions *)funciones{
    if (!_funciones) _funciones = [[Functions alloc]init];
    return _funciones;
}


-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([segue.identifier isEqualToString:@"doneStartEnd"]) {

        [segue.destinationViewController setFecInicioDateV:  self.fecInicioDateSE];
        [segue.destinationViewController setFecFinDateV:     self.fecFinDateSE];

        NSLog(@"fecha inicio StartEvent: %@", self.fecInicioDateSE);
        NSLog(@"fecha fin    StartEvent: %@", self.fecFinDateSE);

    }
}

#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
            selectedCell = @"startDate";
            self.datePicker.date = self.fecInicioDateSE;

            break;
        case 1:
            selectedCell = @"endDate";
            self.datePicker.date = self.fecFinDateSE;
        default:
            break;
    }
}
#pragma mark -


#pragma mark *** Custom methods ***
-(void)comparaFechaInicio{

    if ([self.fecInicioDateSE timeIntervalSinceDate:self.fecFinDateSE] >= 0) {
        if (self.SwitchDate.on)     self.fecFinDateSE = [self.fecInicioDateSE dateByAddingTimeInterval:60*60*24];
        else
            if(!(self.SwitchDate.on))   self.fecFinDateSE = [self.fecInicioDateSE dateByAddingTimeInterval:60*60];
    }

    self.startDateLabel.text    = [df stringFromDate:self.fecInicioDateSE];
    self.endDateLabel.text      = [df stringFromDate:self.fecFinDateSE];

    NSLog(@"Hardcoded date: %@", self.fecInicioDateSE);
    NSLog(@"formatted date: %@", [df stringFromDate:self.fecFinDateSE]);
}

- (void) didBack:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark -


#pragma mark *** Button actions ***
-(IBAction)adjustDate:(id)sender{
    if ([selectedCell isEqualToString:@"startDate"]){

        self.fecInicioDateSE = [self.datePicker date];
        [self comparaFechaInicio];
    }
    else
        if ([selectedCell isEqualToString:@"endDate"]){

            self.fecFinDateSE = [self.datePicker date];
            self.endDateLabel.text  = [df stringFromDate:self.datePicker.date];
        }
}

- (IBAction)saveChanges:(id)sender {
    [self comparaFechaInicio];

    [self performSegueWithIdentifier:@"doneStartEnd" sender:self];
}

-(IBAction)changeDateType:(id)sender{
    if (self.SwitchDate.on){
        self.datePicker.datePickerMode  = UIDatePickerModeDate;
        [df setDateFormat:@"EE, dd MMM YYYY"];
    }
    else{
        self.datePicker.datePickerMode  = UIDatePickerModeDateAndTime;
        [df setDateFormat: @"EE, dd MMM YYYY HH:mm a"];
    }

    [self comparaFechaInicio];
}
#pragma mark -
@end
  • 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-06-17T00:43:30+00:00Added an answer on June 17, 2026 at 12:43 am

    You fell in the same trap that Apple did with recent their Do Not Disturb bug. You want to use yyyy in your NSDateFormatter, not YYYY.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I am writing an app for my school newspaper, which is run completely online
I want to count how many characters a certain string has in PHP, but
I am using JSon response to parse title,date content and thumbnail images and place
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Specifically, suppose I start with the string string =hello \'i am \' me And
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words

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.