Re: Comparing Dates & Timestamps
Re: Comparing Dates & Timestamps
- Subject: Re: Comparing Dates & Timestamps
- From: Jonathan Rochkind <email@hidden>
- Date: Thu, 11 Mar 2004 16:18:00 -0600
Here are the routines I use to set a timestamp to 00:00:00 on a given
day, or 23:59:59(.999) on a given day. The various routines for date
manipulation are confusing. These work for me.
//Leaves day/month/year alone, sets time to max
public static NSTimestamp setToMaxTime(NSTimestamp input) {
java.util.GregorianCalendar cal = new java.util.GregorianCalendar();
cal.setTime(input);
cal.set( java.util.GregorianCalendar.HOUR_OF_DAY, 23);
cal.set( java.util.GregorianCalendar.MINUTE, 59);
cal.set( java.util.GregorianCalendar.SECOND, 59);
cal.set( java.util.GregorianCalendar.MILLISECOND, 999);
return new NSTimestamp( cal.getTime() );
}
//Leaves day/month/year alone, sets time to zero
public static NSTimestamp setToZeroTime(NSTimestamp input) {
java.util.GregorianCalendar cal = new java.util.GregorianCalendar();
cal.setTime(input);
cal.set( java.util.GregorianCalendar.HOUR_OF_DAY, 0);
cal.set( java.util.GregorianCalendar.MINUTE, 0);
cal.set( java.util.GregorianCalendar.SECOND, 0);
cal.set( java.util.GregorianCalendar.MILLISECOND, 0);
return new NSTimestamp( cal.getTime() );
}
At 10:51 PM +0100 3/11/04, David Griffith wrote:
Thanks Art,
On Mar 11, 2004, at 9:49 AM, David Griffith wrote:
I have a date prototype which using the internal value 'Date' - this
shows
as an NSCalendarDate in EOModeler
Sounds like EOModeler is configured to include the "Value Class
(Obj-C)" column instead of "Value Class". You might want to delete the
"Value Class (Obj-C)" column (select the column and press the "Delete"
key) and add "Value Class". But this won't have any effect on the
eomodel itself.
Well both columns contain the same NSCalendarDate in this instance. I have
removed the Value Class (Obj-C) column, however is NSCalendarDate the
incorrect Value Class? I actually looked it up earlier and noticed it was
on Obj-C class. That is the default that EOModeler gave me when I select
internal type of Date.
Now I want to fetch or filter records where:
OrderDate = todaysDate
Can someone tell me an easy way? I have been fiddling with calendars
etc but
not having much luck. I know I can get a new NSTimestamp, but since
this
includes the time also it will not match.
You could get a new NSTimestamp and remove the hours, minutes, and
seconds, but that requires mucking with Java's very clumsy date classes
as you've probably noticed. I think it's rarely safe to compare
timestamps for equality. Instead, test that a timestamp is within a
range of timestamps (untested pseudocode follows):
NSTimestamp today = new NSTimestamp();
NSTimestamp yesterday = today.timestampByAddingGregorianUnits(0, 0,
-1, 0, 0, 0);
EOQualifier qualifier =
EOQualifier.qualifierWithQualifierFormat("orderDate > %@ and orderDate
<= %@", new NSArray(new NSTimestamp[] {yesterday, today});
I am assuming this will give me timestamps for the current time today, and
the same time yesterday. I am looking for say a timestamp for today at
00:00:00 and today at 23:59:59 (as I noticed suggested by Chuck in another
post) but I'm not sure how to get that.
Dave.
Aloha,
Art
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.