Reputation: 9
here i used the sort function for date and time,but it's only sort on date not time,i want sort based on both date and time:
private function dregdate_sortCompareFuction(itemA:Object, itemB:Object):int {
var dt1:Date = DateField.stringToDate(String(itemA.sbatchregdate),"DD/MM/YYYY");
var dt2:Date = DateField.stringToDate(String(itemB.sbatchregdate),"DD/MM/YYYY");
var dateA:Date = new Date(dt1);
var dateB:Date = new Date(dt2);
return ObjectUtil.dateCompare(dateA, dateB);}
kindly please share your knowledge. thanks
Upvotes: 0
Views: 142
Reputation: 2555
As you can see by the format you're passing, DateField.stringToDate only cares about dates and not times.
You could use Date.parse if your input string was in one of these formats:
but yours is not.
So give this, i'd use a Regular Expression to extract the individual values from the string and then build the Date object manually, something like:
var regex:RegExp = /^(\d+)\/(\d+)\/(\d+) (\d+):(\d+)$/i;
var data:Object = regex.exec(itemA.sbatchregdate);
var dateA:Date = new Date(o[3], o[2]-1, o[1], o[4], o[5]);
once you have the two dates created with the proper time values, the comparison should work as expected.
Upvotes: 0