473,748 Members | 5,849 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 14610
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
SimpleDateForma t class to do the sorting of the date fields:

String strDateFormat = "dd-MMM-yyyy";
SimpleDateForma t dfDate = new SimpleDateForma t(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****@localho st.localdomain> wrote in message
news:pa******** *************** *****@localhost .localdomain...
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.b ellglobal.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
12241
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 to sort in Ascending order with the earliest appearing first. The times are stored as follows: 10:30pm
7
2589
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), username, date, and time field like this: 1234 williamstim 01AUG03 7:44:31 2348 williamstim 02AUG03 14:11:20
18
6203
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, date and several other bits of info too. I can do a simple sort over the first field (title as it turns out), and that is fine as far as it gets:
10
3295
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: http://www.ipwebdesign.net/kaelisSpace/useful_tableSort.html This works great except it doesn't sort my UK formatted dates properly, and I end up with something like this: Birth Date (dd/mm/yyyy)
1
2568
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, a transaction type, and a note field. The first three combined are the Primary Key of the table, with the date defined as descending. When I open the table, the records are sorted correctly with the date in descending sequence. However, when I...
2
379
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 (ex. 1/1/2004, 2/1/2003, 3/1/2004...) and not the month or year. Is there a special function I need to try? Note: I noticed that the data type of the field storing the date is "text" and not "date/time." This table is part of a proprietary...
21
3219
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 column. Once the array elements are split, what is the best way to sort them? Thank you. //populate data object with data from xml file. //Data is a comma delimited list of values var jsData = new Array(); jsData = {lib: "#field...
3
2563
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 "*" & "/" & !! & "/" & "*" I have a form called F_DC_Birthday with combo box called ComboBdayMonth. The combo takes information from T_Month table, where I only have two field, first field is the name of Month (eg, January, February...etc) and second field is 01 to 12. The...
0
1243
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 ArrayList that seems to do some tricky stuff with a chache object and I am unable to get any sort of sorting happening.
0
8823
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9530
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9363
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9312
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.