DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3

Thread: comparing dates

  1. #1
    Join Date
    Feb 2005
    Posts
    55

    comparing dates

    hey i want to know how to compare dates that a user has typed in, a user types the date in the text fields provided and I want to be able to compare them. I dont want any output from the method, which i have currently i want it to just compare dates like "compareTo" does for String. Thanks.

  2. #2
    Join Date
    Oct 2004
    Posts
    12
    prepare to undergo ****.

    i learned javascript before java, and still tear my hair out over the mostly Deprecated Date class:
    http://java.sun.com/j2se/1.4.2/docs/...util/Date.html

    you have to use the more urbane Calendar object:
    http://java.sun.com/j2se/1.4.2/docs/.../Calendar.html

    methods you'll probably need:
    set(int year, int month, int date)
    /*you do know how to convert String to primitive int, right?*/

    get(Calendar.SATURDAY);//or whatever day/month in all caps

    getTimeInMillis();

    you make 2 instances of the Calendar object, set their fields with the set() method, then convert them to longs, subtract, then convert the long back to a calendar object, with all the fancy division implied.

    of course, i could be completely off base, and you probably could just do it with the wonderful Date object and compile it with a deprecated sdk, or there could be a method i missed, or you could probably google one up, but there ya go.

    oh, also check out http://www.experts-exchange.com/Prog..._20870994.html

  3. #3
    Join Date
    Sep 2004
    Posts
    223
    then why dont you just convert the date to a string then use the comparTo() method?
    A kram a day keeps the doctor......guessing

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links