Date entry into database through GUI for Date whic

2019-03-05 05:08发布

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

1条回答
女痞
2楼-- · 2019-03-05 05:34

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')))
查看更多
登录 后发表回答