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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:29:39+00:00 2026-05-28T00:29:39+00:00

hope every one is doing well :) I have struck with retrieving the month

  • 0

hope every one is doing well 🙂

I have struck with retrieving the month from the date that is saved in sqlite database.First of all,I would like to thank some of the experts who guided me for proper insertion of a date in to sqlite database table i.e of the following format:

[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

I have displayed all the data including date in a controller page say "View Reminder" page.

Now I have a view controller for the user to view month wise,say if the user selects month "January" from picker view it will navigate to view controller where I display the reminders corresponding to the selected month.

I have earlier got struck at how to access the string value selected from picker view,so that we can use the query:

"SELECT * FROM reminders WHERE Grp = '%@'",appDelegate.groupString

Where groupString is declared in app delegate file,assigned a value in view controller where picker view is present and accessed that string using the above query in display view

which was the solution I found out here .Now I am trying to do the same thing for retrieving dates,i.e. simply write the query as:

"SELECT * FROM reminders WHERE Date = '%@'",appDelegate.monthString

Its not working because the date is saved in @"yyyy-MM-dd HH:mm:ss".So I have made my research on this through various links,I experimented the following ways:

"SELECT * FROM reminders WHERE MONTH like 'January %'" etc..

but as I have mentioned the string selected must be referenced to the value,hence used:

MONTH like '%@',appDelegate.monthString

"SELECT * FROM reminders WHERE strftime('%m', Date) = '%@'",appDelegate.monthString

Gone through sqlite date data types and This Link

None of them worked

As we all know we have a straight forward query for retrieving all the reminders from a specific month:

"SELECT * FROM reminders WHERE Date BETWEEN '2012-01-01' AND '2012-01-31'"

It works perfect,but I need to reference the January, February,March (selected from picker view) etc.. as reference string to date,I am not aware of how to get month part from date.Is there any query for retrieving the month part from a date say 2012-01-01 as January or some other in that particular context….

Please help me,Thanks all in advance 🙂

EDIT:

I have changed the display format in to just month followed by date i.e.:

ReminderClass *remin = [[ReminderClass alloc]init];
remin.Date = [[[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statament, 3)]autorelease];
                
                NSDateFormatter *dateFormat = [[[NSDateFormatter alloc]init]autorelease];
                [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
                NSDate *date = [dateFormat dateFromString:remin.Date];
                [dateFormat setDateFormat:@"MMMM dd"];
                NSString *dateVal = [dateFormat stringFromDate:date];
                remin.Date = dateVal;

But before we do that we need to write the sql query for retrieving data,i.e.:

sqlQuery = [NSString stringWithFormat:@"select * from reminders WHERE ????",appDelegate.monthString];

The question mark is what I need,thanks once again 🙂

  • 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-28T00:29:39+00:00Added an answer on May 28, 2026 at 12:29 am

    First of all we need to form a date manually.To do that we need to create NSDateComponents consisting of the required components in the following way:

    NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:[NSDate date]];
    

    -> Get the current year or present year using the components i.e:

    NSInteger year = [components year];
    

    -> Form the 3 strings year,month,day manually to get From date:

    NSString *fromString = [NSString stringWithFormat:@"%d",year];
    NSString *string2 = [NSString stringWithFormat:@"-%@",appDelegate.monthValue];
    NSString *string3 = @"-01";
    

    appDelegate.monthValue is nothing but the string assigned in appDelegate and assigned with the value selected in pickerView which contains 01,02,03…..12 month values

    As we know 01 is nothing but the day(min range) in any month,we can simply hard-code it:)

    Now we are ready to form the From Date,here we go:

    string2 = [string2 stringByAppendingString:string3];
    fromString = [fromString stringByAppendingString:string2];
    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init]autorelease];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    
    NSString *dateString=[NSString stringWithString:fromString];
    
    NSDate *fromDate = [dateFormatter dateFromString:dateString];
    
    NSString* finalFromDateString = [dateFormatter stringFromDate:fromDate];
    

    Please observe the additional change that I have made to form the date,used 2 strings because we will have a problem when assigning string to NSDate,(improper date retrieval i.e. one day less than the actual date). For more details please follow this link . Now we are finished with from date.

    -> Get the to date using month as reference

    To get to date or max range in a month,we need to use NSRange method which will calculate the range for a month or number of days for a month in that particular year,here it is:

    NSString *toString = [NSString stringWithFormat:@"%d",year];
    
    NSString *monthValue = [NSString stringWithFormat:@"-%@",appDelegate.monthValue];
    
    NSRange monthRange = [gregorian rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit forDate:fromDate];
    
    NSString *rangeString = [NSString stringWithFormat:@"-%d",monthRange.length];
    
    monthValue = [monthValue stringByAppendingString:rangeString];
    
    toString = [toString stringByAppendingString:monthValue];
    
    NSDate *toDate = [dateFormatter dateFromString:toString];
    
    NSString *finalToDateString = [dateFormatter stringFromDate:toDate];
    

    We are done with From date and To date now form the query using the following statement:

    NSString *sqlQuery = [NSString stringWithFormat:@"select * from reminders WHERE Date BETWEEN '%@' AND '%@'",finalFromDateString,finalToDateString];
    

    Thats it,now we must be able to retrieve all the data corresponding to a particular month or the month that is selected in picker view

    Thank you all,have a nice time 🙂

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

Sidebar

Related Questions

I have two data.frame s in R , each indexed by date. One is
it's my first question here and I hope that I'm doing it right. I
Hope everyone is doing well I am having a problem with make files in
i hope that everyone here know the php 'variable variable' syntax: $color = 'red';
Hope I'm asking this correctly: I have a project Projects.Client I have my class
hope someone can help. I have two tables: Users -UserID -UserName UsersType -UserTypeID -UserID
Hope to get solution to this problem. I have been stuck on it since
I'm very new to Ada and one thing that I find hard to grasp
Hey everyone, this seems like it should be a simple one; I really hope
I need to have a RegEx that will match a URI like this based

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.