473,320 Members | 2,088 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,320 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 14592
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.