I am back again with some helpful snippet code. Here using JavaScript we can pro actively sort date fields. Think that you guys are working on a project where in which you guys have used XML as a database to store some relavent data in XML tags. In that XML if you have a date tag or an attribute called date you guys has retrieved all the stuffs related to date tag into an array, now if you want to sort that array you guys (I mean who are not expert in JavaScript) they will use date_array.sort() function. Here is were the developers do mistakes… this will not workout.
Ok.. For Example consider this scenario
var date_array = new Array("12-Jan-2006", "12-feb-2006", "01-Jan-2006", "10-feb-2006");If you guys do in this way, in some scenarios date_array.sort() will not work.
For the above problem you guys can go a head like this:
var mNo=new Object(); // Creating an Object of Actual Number of month - for ex: for jan mention it as 01.
mNo.jan = '01';mNo.feb = '02';mNo.mar = '03';mNo.apr = '04';mNo.may = '05';mNo.jun = '06';mNo.jul = '07';mNo.aug = '08';mNo.sep = '09';mNo.oct = '10';mNo.nov = '11';mNo.dec = '12';
var dateSorting = new Array();
for(i=0; i<date_array.length;i++){
if(date_array!=""){
var tempDate=date_array.split("-");
d=tempDate[0];
tempDate[1]=tempDate[1].toLowerCase();
m=eval("monthNo."+tempDate[1]);
y=tempDate[2];
dateSorting[dateSorting.length]=[Number(y+m+d)];
}
}
dateSorting.sort();
alert("After Sorting: "+dateSorting);What do you say guys, is this snippet is useful?, if you like this post – please do share the same with others. ![]()
Rock Up!!!
Related Entries...
Below is the code which is written in JavaScript, we can use this script for bookmarking the particul ...
John Resig, has explained us a better and interesting way of Method Overloading. Here he has discusse ...
All lovable people of C++, here are sample snippet code which you guys can make use. I want to say o ...
You guys might know the importance of XML, XML (Extensible Markup Language) is a flexible markup lang ...
AIR is rocking in the web world, if you guys! Search for Adobe AIR you will get tons of web snippets ...
Hey folks, hmmm... How can I start.... !!! Yeah, well folks... below is very simple snippet code for ...
Hi Dev Folks, this topic explains you about different patterns used to match character combinations i ...
Hi Guys, I would like to share a JavaScript snippet code which will remove special characters (like ! ...
Making a preloader in flash is very simple. By using ProgressBar and Image Loader components, we can ...
To start with, Well I think bunch of developers might have come across this situations where in which ...























Leave Your Response