Compare Two Dates





7
Date Submitted Wed. Feb. 22nd, 2006 12:58 AM
Revision 1 of 1
Coder mattrmiller
Tags Compare | Date | Java
Comments 2 comments
Compare two dates in Java.


// Compare two dates
        public static boolean compareDates(Date dDateA, Date dDateB)
        {
                // Declare variables
                GregorianCalendar cDateA = new GregorianCalendar();
                GregorianCalendar cDateB = new GregorianCalendar();
               
                // Set dates
                cDateA.setTime(dDateA);
                cDateB.setTime(dDateB);
               
                // Compare
                if (cDateA.get(Calendar.MONTH) == cDateB.get(Calendar.MONTH) && cDateA.get(Calendar.YEAR) == cDateB.get(Calendar.YEAR) && cDateA.get(Calendar.DAY_OF_MONTH) == cDateB.get(Calendar.DAY_OF_MONTH))
                {
                        return true;
                }
               
                return false;
        }

 

Matthew R. Miller

www.bluecreststudios.com
=================
Matthew R. Miller

http://bluecreststudios.com
http://www.codeandcoffee.com

Comments

Comments Way more simple
Sat. Jun. 7th, 2008 5:02 PM    Beginner me
Comments A minor improvement
Mon. Apr. 3rd, 2006 10:06 AM    Helper jpinkham

Voting