Dates in Scripts

Hi there-

I have been working with screen scraper for awhile now and LOVE it! Quick question though. I am new to the java language and don't know the correct syntax to use for this. I have a script where I have to change the date variable each day to pull in that days information. Is there a way to write some sort of IIf statement in java so it will go back one day vs me having to change the date each day. Just thought I would ask.

Jason

I have a script I reuse a lot

I have a script I reuse a lot to do things like that

import java.util.*;
import java.text.*;

// //////////////////////////////////////
//
// Script to add a number of
// days to the current date.
//
// Updated 1-Aug-06 by Jason.
//
// //////////////////////////////////////

// Set number of days to add to current date.
addDays = 7;

// Set the format in which the date should be output.
String dateFormat = "M/d/yyyy";

Calendar rightNow = Calendar.getInstance();
rightNow.add( Calendar.DATE, addDays );
Date endDate = rightNow.getTime();
SimpleDateFormat formatter = new SimpleDateFormat( dateFormat );
String newDate = formatter.format( endDate );

// Output the new date.
session.log("+++New date: " + newDate);
session.setVariable("NEW_DATE", newDate);

Jason Thanks for the hint.

Jason

Thanks for the hint. Here is a another problem i am having. Below is my code for the output, how can I get it to reformat the reportDate variable?


FileWriter out = null;

try
{
session.log( "Writing data to a file." );

// Open up the file to be appended to.
out = new FileWriter( "phasar_scrape.txt", true );

// Write out the data to the file.
out.write( session.getVariable("reportDate")+ "\t" );
out.write( session.getVariable("emp")+ "\t" );
out.write( dataRecord.get( "ORG" ) + "\t" );
out.write( dataRecord.get( "DEST" ) + "\t" );
out.write( dataRecord.get( "CONS" ) + "\t" );
out.write( dataRecord.get( "CONTAINER" ) + "\t" );
out.write( dataRecord.get( "TOTAL" ) );
out.write( "\n" );

// Close up the file.
out.close();
}
catch( Exception e )
{
session.log( "An error occurred while writing the data to a file: " + e.getMessage() );
}

Give this a

Give this a look:

http://community.screen-scraper.com/API/reformatDate

Thanks Jason I am still

Thanks Jason

I am still confused in the correct syntax of how to write it in my script? Any ideas. I tried it several ways but keep getting errors.

Personally I would: // Write

Personally I would:

// Write out the data to the file.
date = session.reformatDate(session.getVaraible("reportDate"), "yyyy-MM-dd", "dd-MMM-yy");
out.write( date + "\t" );

But you could

// Write out the data to the file.
out.write( session.reformatDate(session.getVaraible("reportDate"), "yyyy-MM-dd", "dd-MMM-yy")+ "\t" );

Awesome I tried your

Awesome

I tried your recommendation, but keep getting this error in the log file. Do I need to import a java class?

The error message was: Error in method invocation: Method getVaraible( java.lang.String ) not found in class'com.screenscraper.scraper.ScrapingSession' : at Line: 13.

Misspelled "variable" ... I

Misspelled "variable" ... I do that all the time.