I am adding dates into dictionary as the key and the corresponding value as some text ,but I am converting the date into string ,before adding to a dictionary,I have written the below code
[dateNoteDict setValue:datestring forKey:notes.text];
but before adding to dictionary I want to make some date comparision such that ,if the date present in dictionary is greater than ,the nest date then ,I should add below in the dictionary and so..on..
But I am not understanding how to do that.
So friends,please help me out..
Regards
Ranjit
You should do the comparison before converting the dates into NSStrings.
Assuming you are using NSDate objects, you can use the compare method. Have a look at this answer from S.O about date comparison.
Set some particular date format while setting as key in your dictionary. You can use NSDateFormatter for this. Also convert new date in the same format and then use "compare" for date comparison.
Thanks
Related
I'm trying to apply a filter on realm which includes a Date but with no luck.
I've found out that Date object cannot be passed because the %# format expects a Foundation object as argument, so I've applied a cast to NSDate.
let newDate = Date()
realm.objects(E.self)
.filter(String(format: "%# <= %#", key, newDate as NSDate)).first
The issue that appears is "Unable to parse the format string timestamp==2020-03-20 08:21:00 +0000"
key is the name of the field, which in this case it is "timestamp" and on the model it has the type Date.
Any input is appreciated.
Thanks
You should use:
.filter("\(key) <= %#", newDate as NSDate)
This is calling the overload of Realm's filter method that accepts a format and arguments.
String(format:) is not the right thing to use here, as that just does general string formatting. But here, you want the date to be formatted according to the rules of NSPredicate formats. On the other hand, the key can just be interpolated into the string because the name of the table column doesn't need a special format.
If key comes from a UITextField or something like that, then you might need to beware of injection attacks as well, and validate and/or escape the key properly beforehand.
I need to recover date from mongodb iso date formate by angular js. How can I recover this? please help me.
Mongodb iso date: 2013-12-28T08:30:17.795Z
My convert type: 28-12-2013 8:30:17
Maybe something like:
var date = new Date("2013-12-28T08:30:17.795Z");
$scope.displayDate = date.toLocaleString();
I really recommend http://momentjs.com/. they have a good format function.
Ex.
moment('2013-12-28T08:30:17.795Z').format('DD-MM-YYYY HH:mm:ss');
Will give the answer
28-12-2013 08:30:17
Its very easy to get the time as per mongo,
get the value in your controller from the mongoDB.
Use that value to store in the variable.
Convert it to the ISO format easily using .toISOString() method and its done.
Here is sample..
getdate.controller(..){
$scope.fromdate=date.toISOString();
console.log($scope.fromdate);
}
Now you can get in the MongoDB format..
I have a date string in the format "2013-01-31T10:10:05.000Z". I want to convert this string to a Date object in extjs.
I have tried to use Ext.Date.parse("2013-01-31T10:10:05.000Z","Y-m-dTH:i:s.uZ"). But it is returning undefined.
I also tried with new Date("2013-01-31T10:10:05.000Z"), but it is also returning undefined.
Note: I have tried in IE8 browser.
Could anyone please help me to convert the above date string to Date object?
Thanks a lot sra. Now I am getting the result as ...UTC+5:30... Is there any way to convert this in IST format?
Try Ext.Date.parse("2013-01-31T10:10:05.000Z","c");
The c is the format type for ISO 8601 formatted dates
See the Ext.Date API for more details on this or other available formats
That's because 'T' and 'Z' are special characters in the Date format: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.Date
You have to escape them like this: Ext.Date.parse("2013-01-31T10:10:05.000Z","Y-m-d\\TH:i:s.u\\Z")
I want to add date into my database ..
and I want to add it in some specific format ..like dd/mm/yyyy
how to check the validation for it?
Like e-mail validation .. I want to check is it in specified format or not?
how to do this ?
1) What is the input method for your date?
If it is thru a UIDatePicker, you have nothing to do, the UIDatePicker will return a valid NSDate. I encourage you to manipulate NSDate objects and use UIDatePickers as date inputs especially to avoid the question of date validation.
If it is thru a text field, you can set the UITextField's inputView to an UIDatePicker and you won't have to bother about date validation either as you will obviously directly have a (parsed) NSDate that you can manipulate directly, being sure it is valid.
Then in either case, use NSDateFormatter to convert your NSDate (entered by the user thru UIDatePicker) to an NSString (to insert in your database).
2) If you have a plain text entered by the user thru the keyboard, and can't or don't want to use a UIDatePicker (even as the inputView of your UITextField), you can convert your NSString to an NSDate thru an NSDateFormatter to check if it returns a non-nil NSDate (meaning it is a valid date).
Note: You may also use NSRegularExpression or NSPredicate classes to check the format of your string... but you won't have the subtleties of NSDate validation (like checking that 31/02/2011 or 67/13/99 is invalid)
i have strings who look like this 20110525 .
how can i make to put '-' caracters in NSString variable ? to let dates look like this 2011-05-25 ?
My second question is how can i sort the dates to make the table look like this 20110525 then 20110526 ?Help please . Thank you
Why not just use the NSDate class to get the date, and use an NSDateFormatter to format the date the way you want.
you can try using sscanf(input,"%4d%2d%2s",&year,&month,&day) to parse input string and sprintf(output,"%d-%d-%d",year,month,day) to format your date.