Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2013
    Location
    Wisconsin, USA
    Posts
    60
    Rep Power
    0

    Default Getting the number of days between 2 date fields

    The title says all. I want to output the number of days between the present date and the date of hire for an employee, so he/she can see the number of days he/she has been with the company. Here's my code:

    Java Code:
    /*
     * This class provides information to identify an employee, and how long he/she
     * has been with a company. Note that the employee id must be inthe format 
     * XXX-L, where each X is a digit within the range 0-9, and L is a letter within
     * the range A-M.
     */
    package employment;
    import org.joda.time.DateTime;
    
    //http://joda-time.sourceforge.net/quickstart.html
    
    public class Employee {
        
        public static String Name;//using "static" enables us to reuse Name in 
        //subclasses     
        public static int employeeNum;//the XXX portion of the employee id
        
        public static char employeeNumLetter;//the L portion of the employee id
        
        public static DateTime presentDate;
        
        public static DateTime hireDate;    
        
        static int Seniority; //get the number of days an employee has been with the
        //company.
        
        
        
        public Employee(String name, int empNum, char empLetter, DateTime present, 
                DateTime hired, int senior)
            {
                Name = name;
                employeeNum = empNum;
                employeeNumLetter = empLetter;            
                presentDate = present;
                hireDate = hired;             
                Seniority = senior;            
            }
            
            //Write one or more constructors and the appropriate accessor and 
            //mutator methods for the class. (Note that "accessor methods" are 
            //getters, and "mutator methods" are setters):
    
       
       //The setName method accepts an argument
       //that is stored in the Name field.     
       public void setName(String name)
       {
          Name = name;
       }   
       //The getName method returns the value
       //stored in the Name field.  
       public String getName()
       {
          return Name;
       }       
       
    
       public void setEmployeeNum(int empNum)
       {
          employeeNum = empNum;
       }    
       public int getEmployeeNum()
       {
          return employeeNum;
       }
       
       
       public void setEmployeeNumLetter(char empLetter)
       {
          employeeNum = empLetter;
       }      
       public int getEmployeeNumLetter()
       {
          return employeeNumLetter;
       }
            
    
       public void setHireDate(DateTime aHireDate)
       {
          hireDate = aHireDate;
       }
       public DateTime getHireDate()
       {
          return hireDate;
       }
       
       
       //The setSeniority method accepts the current date and the employee's date 
       //of hire as arguments, and uses them to calculate how many days they've 
       //been with the company.    
       public void setSeniority(DateTime present, DateTime hired)
       {
          //presentDate - hireDate = Seniority;
          //http://stackoverflow.com/questions/3802893/number-of-days-between-two-dates-in-joda-time
          Days.daysBetween(presentDate.withTimeAtStartOfDay() , hireDate.withTimeAtStartOfDay() ).getDays();
          //error: cannot find symbol
          //symbol:   variable Days
          //location: class Employee
          
       }
       
       //The getSeniority method returns the number of days from the date that was
       //calculated in the setSeniority method.      
    
       public int getSeniority()
       {
          return Seniority;//number of days employee has been with company
       }
             
    
    }//end of Employee class (the super class)
    My error is on line 96. Any ideas?

  2. #2
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    268
    Rep Power
    2

    Default Re: Getting the number of days between 2 date fields

    What exactly is Days?

  3. #3
    Join Date
    Jul 2013
    Location
    Wisconsin, USA
    Posts
    60
    Rep Power
    0

    Default Re: Getting the number of days between 2 date fields

    Well, Days is Seniority (the number of days an employee has been with the company). If you're wondering why I didn't use this:

    Java Code:
    Seniority.daysBetween(presentDate.withTimeAtStartOfDay() , hireDate.withTimeAtStartOfDay() ).getDays();
    Instead of this:

    Java Code:
    Days.daysBetween(presentDate.withTimeAtStartOfDay() , hireDate.withTimeAtStartOfDay() ).getDays();

    It's because when I change Days to Seniority, I get the error message "int cannot be dereferenced".


    I got the line of code from here.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Getting the number of days between 2 date fields

    Don't just copy and paste code and expect it to work.
    Days is another Joda class.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. number of the days (-) days gone past
    By sh4rif in forum New To Java
    Replies: 4
    Last Post: 05-22-2012, 02:17 PM
  2. Checking date lying between two days of month
    By vkram.singla in forum New To Java
    Replies: 7
    Last Post: 03-07-2012, 10:53 AM
  3. days remaining to a particular date
    By aconti in forum New To Java
    Replies: 1
    Last Post: 05-30-2011, 01:16 PM
  4. how to get 10 days prior system date
    By vanitha nanda in forum Java Applets
    Replies: 7
    Last Post: 09-27-2009, 02:45 AM
  5. adding days to a date
    By karen.tao in forum Java Applets
    Replies: 13
    Last Post: 09-13-2009, 10:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •