Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Change day in date through coding.

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 417
    Comment on it

    The following code changes the day from the given "date" for example: if you want to add or subtract 5 days from the date put a value 5 or -5 respectively for "timeSliceDay".

    -(NSString *)getTimeSliceDate:(NSString *)date format:(NSString *)format returnFormat:(NSString *)returnFormat timeSliceDay:(int)timeSliceDay{
        NSDate *dated = [self dateFromString:date format:format];
    
        dated = [dated dateByAddingTimeInterval:timeSliceDay*24*60*60];
        return [self stringFromDate:dated format:returnFormat];
    }
    
    -(NSDate*)dateFromString:(NSString *)dateString format:(NSString *)format {
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:format];
        return [formatter dateFromString:dateString];
    }
    -(NSString*)stringFromDate:(NSDate *)date format:(NSString *)format {
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:format];
        return [formatter stringFromDate:date];
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: