Results 1 to 4 of 4

Thread: Yesterday's Date? - RESOLVED!

  1. #1

    Thread Starter
    Hyperactive Member rockies1's Avatar
    Join Date
    Jul 1999
    Location
    Stuck at work
    Posts
    375

    Yesterday's Date? - RESOLVED!

    I have some code that works to calculate yesterday's date and it has worked great, until today.

    Anyone have something that works correctly?

    Here's mine:
    Code:
    		public static String CalcYestDate()
    		{
    			//Set up date to run for
    			java.util.Calendar  gc;
    			java.util.Date  curDate;
    			String  strCurDate = null;
    			String fileDate = new String();
    
    			gc = GregorianCalendar.getInstance ( ); // Gets the current Calendar instance
    			gc.roll(gc.DATE,false);
    
    			curDate = gc.getTime ( ); // Gets the Date time part of gc
    			SimpleDateFormat sdf2 = new SimpleDateFormat ( "yyyyMMdd" ); //sets up the correct format for the date
    			fileDate = sdf2.format ( curDate );  //Changes the date into the correct date format
    
    			return(fileDate);
    	}//End CalcYestDate
    When I ran it today it returned 20030731 instead of 20030630.

    Thanks!

    Morgan
    Last edited by rockies1; Jul 1st, 2003 at 03:20 PM.
    Morgan
    [email protected] - Home
    [email protected] - Work
    Using VB6 SP6 but trying to learn VB2005EE

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    import java.util.Date;
    import java.text.DateFormat;

    Code:
      public class D{
        public static void main(String[] args){
    
        long day = 60 * 60 * 1000 * 24;   
    
        Date today = new Date(System.currentTimeMillis()); 
        DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
     
        System.out.println(df.format(today)); 
     
        today.setTime(today.getTime() - day); 
    
        System.out.println(df.format(today));      
       }
     }

  3. #3

    Thread Starter
    Hyperactive Member rockies1's Avatar
    Join Date
    Jul 1999
    Location
    Stuck at work
    Posts
    375
    Worked perfectly, thank you!!

    Morgan
    [email protected] - Home
    [email protected] - Work
    Using VB6 SP6 but trying to learn VB2005EE

  4. #4

Posting Permissions

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



Click Here to Expand Forum to Full Width