Date entry into database through GUI for Date which is readable by FMDatabase
Asked Answered
C

1

0

I have a set of events which I will have to feed into the database before I ship the app so that the application is ready to read from this database.

I have seen some posts like these which explain how to enter NSDate into database so that it can be read back:

  1. iPhone SQLite date problem
  2. Persisting Dates to SQLite3 in an iPhone Application

Now, I want to entry dates into the database by running queries like:

insert into VendorEvents (event_start, event_end, notes, event_name) values (date('2012-01-26'), date('2012-01-26'), 'Republic day of India is the day when our constitution was framed and put into practice', 'Republic day')

When I run this query through MesaSQLite application, the returned results are perfect as expected:

select * from VendorEvents where ((event_start between '2011-12-01 00:00:00 +0000' and '2012-02-01 00:00:00 +0000') or (event_end between '2011-12-01 00:00:00 +0000' and '2012-02-01 00:00:00 +0000'))

But when I run the same query through FMDatabase inside the application, no records are returned.

The datatype of the first and second field in VendorEvents in my database is of type "Date". The only difference in the way I am entering the data is by using MesaSQLite application. So, is there any mistake I might be doing due to which I am not getting the results in FMDatabase?

Thanks, Raj

Chainplate answered 7/1, 2012 at 19:56 Comment(0)
L
1

Use the date() function. Have a try:

select * from VendorEvents 
where ((event_start between date('2011-12-01 00:00:00 +0000') and date('2012-02-01 00:00:00 +0000')) 
    or (event_end between date('2011-12-01 00:00:00 +0000') and date('2012-02-01 00:00:00 +0000')))
Livingstone answered 9/5, 2012 at 9:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.