From: "Albert Jagnow" <email@hidden>
To: "Jonathan Fleming"
<email@hidden>,<email@hidden>
Subject: RE: NSNumberFormatter & NSTimestamp -- Not Happening
Date: Tue, 16 Sep 2003 09:48:33 -0500
>1.) I have created a custom number formatter to give me a BigDecimal on
a
>'price' textField. This works fine on the WOTexField in WOBuilder, but
when
>I make the save to the database (MSSQLServer2000), instead of 345.45 I
only
>get 345 what am I missing in this senario
What is the column type in the database? Is it possible you set the
column type to integer?
>2.) I want to establish the lapsed time between two dates so that I can
>perform an automatic delete if an EO has not been updated for that
legth of
>time. Eg. if the last modified date is Sep 01 2003 and the current date
is
>Oct 01 2003 (1 month or 31 days later) I want to perform a delete, how
would
>i write this please?
If you have two NSTimestamps you can get the number of days between them
using a method something like this:
//this is untested code
public int numOfDays(NSTimestamp start, NSTimestamp end){
long diff = (end.getTime() - start.getTime()); //diff in ms
int days = (int)( diff / (24*60*60*1000) );
return days;
}
NSTimestamp now = new NSTimestamp();
if(numOfDays(myObject.timestamp,now) > 60){ //delete objects older than
60 days
//delete myObject
}
or if what you want to do is delete objects with the date earlier than
the first of the month two months ago, i.e. keep the current month and
two months history, you might do something like this:
public NSTimestamp compareTimestamp(){
NSTimestamp now = new NSTimestamp();
NSTimestamp then =
now.timestampByAddingGregorianUnits(0,-2,0,0,0,0);//-2 for months ago
GregorianCalendar myCal = new GregorianCalendar();
myCal.setTime(then);
int year = myCal.get(GregorianCalendar.YEAR);
int month = myCal.get(GregorianCalendar.MONTH) + 1;
NSTimeZone tz =
NSTimeZone.timeZoneWithName("America/Chicago",true);
return (new NSTimestamp(year,month,1,0,0,0,tz) );
}
NSTimestamp ct = compareTimestamp();
if(myObject.timestamp.before(ct)){
//delete myObject
}
--Albert
This e-mail (including any attachments) is covered by the Electronic
Communications Privacy Act, 18 USC. 2510-2521. It is confidential and
may be legally privileged. If you are not the intended recipient, you
are hereby notified that any retention, dissemination, distribution, or
copying of this communication is strictly prohibited. Please reply to
the sender that you have received the message in error, and then delete
it. Thank you.