Sqlite query to fetch rows for particular day - ios

I would like to fetch results for selected date using SQLITE DB, and am getting date from uidatepicker and passing to fetch results method.
My sqlite query is following,
SELECT * FROM TRANSACTIONSHISTORY WHERE DATE > "21-09-2014 12:00:00" AND DATE < "22-09-2014 00:00:00"
But for that am getting results in 2015 year also, kindly help me to get out of this issue.

Your date is not in the correct format, if you check the documentation (http://www.sqlite.org/lang_datefunc.html) you will find this:
A time string can be in any of the following formats:
YYYY-MM-DD
YYYY-MM-DD HH:MM
YYYY-MM-DD HH:MM:SS
YYYY-MM-DD HH:MM:SS.SSS
YYYY-MM-DDTHH:MM
YYYY-MM-DDTHH:MM:SS
YYYY-MM-DDTHH:MM:SS.SSS
HH:MM
HH:MM:SS
HH:MM:SS.SSS
now
DDDDDDDDDD
If you make your date one of these formats, and run the query it will work:
SELECT * FROM TRANSACTIONSHISTORY WHERE date BETWEEN '2014-09-21' AND '2014-09-22'

Related

Convert ISO date format to moment date format

In angular material, used mat-datepicker for showing date picker.
I need to show custom date formatter in that date field.For custom date formatter, I have used material-moment-adpator. But I have ISO date format like this dd-MM-yyy. If use this date format, I get Tu-01-1990 output but I need to get a 10-01-1990.
How to convert iso date format to moment date format?
for "numeric" days, you should use DD instead of dd

Getting next date when trying to convert NSDate to String

I have this date in actuall
2016-09-03 19:00:00 +0000
Now I am trying to convert it to String using a specific format like below
But what I am getting in return is not as desired. the formatter is adding on day to the given date like below
Is this standard behaviour ?
This is not standard behaviour. This happen because of the time zone difference. Set time zone proper
Set the timezone.
formatter.timeZone = [NSTimeZone timeZoneWithAbbreviation: #"GMT"];
When you hover over the date, you can see that it is showing UTC, whereas the formatter is automatically converting this to a local date. If your timezone is 5 hours ahead of UTC, then it will be the next day locally from that time.

NSDateFormatter for this format

I want to make an NSDateFormatter object for this date format (for example):
2016-04-15 15:00:00
I've tried yyyy-mm-dd hh:mm:ss but then when I am trying to attach it to a date like that:
date = [formatter dateFromString:dateString];
It gives me nil.
what is the correct way to do it?
Thank you!
set date format as
2016-04-15 15:00:00
yyyy-MM-dd HH:mm:ss
your date string is 24 hour format
Here's all you need for date formatting:
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html
There's a list of link under the Fixed Format title where you can see in detail the different formats for whatever you want, for iOS7 and greater see this:
http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns

Data retrieving from sqlite DB between two dates - using objective c

I am using the below query with date filtering, but I am getting wrong result.
SELECT * FROM TRANSACTIONSHISTORY
WHERE DATE > "29-01-2015 12:00:00"
AND DATE < "30-01-2015 00:00:00" AND USERID=abc
I am getting result with date column with value of 29-Jan-2016 records, what am I missing here, can any one help me to get out of this value.
The date format in your SQL will not work because SQLite doesn't have a native datetime type, so it's generally stored either as a string, in YYYY-MM-DD HH:MM:SS.SSS format, or as an numeric value representing the number of seconds since 1970-01-01 00:00:00 UTC. See date and time types on SQLite.org. Note that if you're using the string representation that the sequence is year, month, day (which, when sorting/querying this string field, the this alphanumeric string will sort correctly by year first, then month, and then day, which is critical when doing queries like yours).
If you really stored dates in the database as a string in the DD-MM-YYYY HH:MM:SS format, you should consider changing the format in which you saved the values into one of the approved date formats. It will make the date interactions with the database much, much easier, allowing queries like the one you asked for (though, obviously, with DD-MM-YYYY replaced with YYYY-MM-DD format).
You have cast your string to Date
SELECT * FROM TRANSACTIONSHISTORY WHERE DATE between Datetime('29-01-2015 12:00:00') and Datetime('30-01-2015 00:00:00') AND USERID=abc
The first answer is exactly what you need. What you did in your code would be comparing strings using ASCII values.
I would recommend you to use the linux time stamps like: 1453818208, which is easier to save and compare. In addition, it can always be translated to human-readable dates like: 29-01-2015 12:00:00.
SELECT * FROM TRANSACTIONSHISTORY
WHERE DATE > "29-01-2015 12:00:00"
AND DATE < "30-01-2015 00:00:00" AND USERID=abc
I hope this helps you :)
Try this first try without Time,after that try date and time both , Hope i will work for you
SELECT TRANSACTIONSHISTORY
FROM SHIPMENT
WHERE DATE
BETWEEN '11-15-2010'
AND '30-01-2015'
// you can try this one also
SELECT * FROM TRANSACTIONSHISTORY WHERE DATE BETWEEN "2011-01-11" AND "2011-8-11"

Use DATETIME and TIME of sqlite query in Core data

What is the predicate equivalent of SQL query
DATETIME('now','+0 seconds’) > DATETIME(ZDATE,TIME(ZEND_TIME))
where
ZDATE is date in format YYYY-MM-DD HH:mm:ss
ZEND_TIME is date in format YYYY-MM-DD HH:mm:ss
I am getting the following error when I am directly using it in NSPredicate
Unable to parse function name 'DATETIME' into supported selector (DATETIME)

Resources