473,390 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

Sort Date Field String

Hi:

I am already using TreeMap to massage records in my export file such that
each record has a unique key combination ( LastName + FirstName + Member
Key) . Thus I am sorting the records by the unique key. I also have a Date
String Field in my record ( ie "30-Apr-2005" ). I want to create a unique
key combination of
( LastName + FirstName + Member Key + Date).

Can you please tell me what are the steps I need to do to sort the Date
String Field? Obviously, I can't treat the date as a string field because
it will sort the date alphabetically ( ie 30-Apr-2005 will come before
30-Jan-2005 ).


Thanks in advance

Andrew
Oct 4 '05 #1
3 14597
Den Tue, 04 Oct 2005 09:12:58 -0400. skrev andrew:
I am already using TreeMap to massage records in my export file such that
each record has a unique key combination ( LastName + FirstName + Member
Key) . Thus I am sorting the records by the unique key. I also have a Date
String Field in my record ( ie "30-Apr-2005" ). I want to create a unique
key combination of
( LastName + FirstName + Member Key + Date).


What about making/using a method for turning dates into an int or long.
Then making a SortedMap using the number as key and string as value.

It's all about making/using a fast algorithm for the convertion.

--
Programmers should realize their critical importance and responsibility in a
world gone digital. They are in many ways similar to the priests and monks of
Europe's Dark Ages; they are the only ones with the training and insight
to read and interpret the "scripture" of this age.

Oct 4 '05 #2
Thanks for the reply. I found a solution by using Date, and
SimpleDateFormat class to do the sorting of the date fields:

String strDateFormat = "dd-MMM-yyyy";
SimpleDateFormat dfDate = new SimpleDateFormat(strDateFormat);
Date dateKey = null;
dateKey = dfDate.parse( datefield ); // datefield has the
string value "31-Jan-2005" etc.
Then I can put dateKey as part of the key in a TreeMap so that it can be
sorted. :)

Thank you.
"Thomas Dybdahl Ahle" <th****@localhost.localdomain> wrote in message
news:pa****************************@localhost.loca ldomain...
Den Tue, 04 Oct 2005 09:12:58 -0400. skrev andrew:
I am already using TreeMap to massage records in my export file such that each record has a unique key combination ( LastName + FirstName + Member
Key) . Thus I am sorting the records by the unique key. I also have a Date String Field in my record ( ie "30-Apr-2005" ). I want to create a unique key combination of
( LastName + FirstName + Member Key + Date).
What about making/using a method for turning dates into an int or long.
Then making a SortedMap using the number as key and string as value.

It's all about making/using a fast algorithm for the convertion.

--
Programmers should realize their critical importance and responsibility in

a world gone digital. They are in many ways similar to the priests and monks of Europe's Dark Ages; they are the only ones with the training and insight
to read and interpret the "scripture" of this age.

Oct 4 '05 #3
In article <Ob******************@news20.bellglobal.com>, an****@abc.com
writes...
Hi:

I am already using TreeMap to massage records in my export file such that
each record has a unique key combination ( LastName + FirstName + Member
Key) . Thus I am sorting the records by the unique key. I also have a Date
String Field in my record ( ie "30-Apr-2005" ). I want to create a unique
key combination of
( LastName + FirstName + Member Key + Date).

Can you please tell me what are the steps I need to do to sort the Date
String Field? Obviously, I can't treat the date as a string field because
it will sort the date alphabetically ( ie 30-Apr-2005 will come before
30-Jan-2005 ).


Date objects store the date as the number of milliseconds since a
particular point in time.

Instead of storing your dates in human readable form as a String, store
the number instead. That way you can sort and compare very quickly.

You can also reconstruct a Date object from the number any time you like
and use standard Java date manipulation and comparison techniques with
it.

--
DM
personal opinion only
Oct 6 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: 00steve | last post by:
Hi, I have a group of records that I need to sort by time field. The time field is a text string (should've been a date/time - I know -doh!) I was wondering if anyone knew how to write a query...
7
by: Nova's Taylor | last post by:
Hi folks, I am a newbie to Python and am hoping that someone can get me started on a log parser that I am trying to write. The log is an ASCII file that contains a process identifier (PID),...
18
by: googleboy | last post by:
I didn't think this would be as difficult as it now seems to me. I am reading in a csv file that documents a bunch of different info on about 200 books, such as title, author, publisher, isbn,...
10
by: Colin Steadman | last post by:
I'm a stupid ASP programmer and I dont do Javascript (except for very simple tasks anyway), and I'm in a bit of a predicament. I've used a javascript table sorting script from here: ...
1
by: phony | last post by:
I have a subform attached to a main form. The linkage is from the main Id which is also a field in the table from which the subform is built. The table contains four fields, the main id, a date,...
2
by: Tim Lang | last post by:
I'm trying to sort results of a query of a number of fields from two tables by a date field in one of them. However, it keeps sorting the date based only on the first number ("day") of the date...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
3
by: HowHow | last post by:
I need to sort the "DateOfBirth" by the day (dd) regarless of month (mm)and year (yyyy). I have a query called q_DC_Client, in criteria, I am using this code below: Like "*" & "/" & !! & "/" & "*"...
0
by: pbd22 | last post by:
Hi. I am returning to an old bit of code in our program and need to figure out how to sort my columns on bind. I am sorting on Date (mostly) and some other values. Problem is, the code is an...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.