MagicalRecord date parsing - ios

I've got a date in the following format:
2013-05-04T05:07:09+00:00
I'm using MagicalRecord to map the NSDate automatically. As far as I can see the above date format should comply with MagicalRecord's default date format: yyyy-MM-dd'T'HH:mm:ss'Z'.
I have tried with a custom dateFormat entry in the attribute's user info (see this article):
yyyy-MM-ddTHH:mm:ss+Z, yyyy-MM-dd T HH:mm:ss Z, yyyy-MM-dd'T'HH:mm:ss'+'Z
but none of them work in order to have it parse the date properly and it always returns nil regardless of setting a custom dateFormat or using MagicalRecord's default format.

Let's look at your string:
2013-05-04T05:07:09+00:00
This is:
four digit year
hyphen
zero-padded month
hyphen
zero-padded day of month
'T' character
zero-padded hour
':' character
zero-padded minute
':' character
zero-padded second
timezone (with direction from GMT and a separating colon)
Thus, according to the date format specifiers documentation, the pattern you'd want is:
yyyy-MM-dd'T'HH:mm:ssZZZZZ
Also, be sure to use the en_US_POSIX locale with the NSDateFormatter.

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

TDatetimePicker format shows wrongly

If i set the property "format" of a TDateTimePicker component (Delphi XE10) eg. ddd d/m/yyyy then it shows Tue 14/47/2016 !! and the date 31/12/2016 as 31/0/2016 !
what is happening, please ?
That date format is incorrect. You need to use uppercase M, as is shown in the TDateTimePicker.Format documentation. Lower-case m represents minutes in a time format.
m The one- or two-digit minute.
mm The two-digit minute. Single-digit values are preceded by a zero.
M The one- or two-digit month number.
MM The two-digit month number. Single-digit values are preceded by a zero.
MMM The three-character month abbreviation.
MMMM The full month name.
ddd MM/dd/yyyy shows Tue 06/14/2016, and ddd dd/MM/yyyy shows Tue 14/06/2016.

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"

NSDateFormatter zeroing minutes

When converting a date string for the server into a NSDate - which is in this format
2012-09-07T11:57:44+10:00
we're using this dateFormat in NSDateFormatter
yyyy-MM-dd'T'HH:mm:ssZZZ':'mm
but the minutes are always zero minutes.
The second "mm" overwrites the result of the first and sets minutes to zero, having parsed the "00" on the end of the timezone.
In order to parse that format of timestamp you must first somehow remove the last : character, as NSDateFormater cannot handle that.

How to automatically format NOW() in to a string that that displays YYYY-MM-DD?

Is it possible to format the output of NOW() to a string that displays YYYY-MM-DD?
This is the output of NOW(): 29/02/2012 12.07.37
The reason is, that I need to use the current date in a QUERY.
QUERY only accepts date in the format YYYY-MM-DD . I can't get a date directly from a cell, because it gets formatted as (even if I change the formatting): DD/MM/YYYY
Perhaps some regular expression?
If this is supposed to be an in-cell formula then you can use
=TEXT(NOW(),"yyyy-mm-dd")
I will follow JMax's suggestion and convert my comment to an answer.
Now() returns the current date and time as a number. The integer part gives the date and the fraction part gives the time. If you print or display that date, the default is to give the full date in what Microsoft think's is the local format.
Format(expn, fmt) allows you to convert an expression to a string. For example:
Dim DateStg as String
DateStg = Format(Now(),"yyyy-mm-dd")
fmt defines the format to which the expn is to be converted. fmt is a mixture of code letters (such as: "yyyy", "mm", "dd") and punctuation (such as "-"). "yyyy-mm-dd" appears to meet your current needs but you can also usethe following to format dates:
"mmm" to give three letter month (Jan, Feb, etc.)
"mmmm" to give full name of month (January, February, etc)
"ddd" to give three letter day of week (Mon, Tue, etc)
"dddd" to give full name of day of week (Monday, Tuesday, etc)
In VB.net you can do the following:
Dim dateStr As String = Now().ToString("yyyy-MM-dd")
In C# you can do it like this:
String dateStr = DateTime.Now.ToString("yyyy-MM-dd");

Resources