Re: Comparing Dates & Timestamps
Re: Comparing Dates & Timestamps
- Subject: Re: Comparing Dates & Timestamps
- From: David Elsner <email@hidden>
- Date: Fri, 12 Mar 2004 09:26:37 +1100
I use this:
GregorianCalendar myCalendar = new GregorianCalendar();
NSTimeZone tz = NSTimeZone.timeZoneWithName("Australia/Sydney", true);
int year = myCalendar.get(GregorianCalendar.YEAR);
int month = myCalendar.get(GregorianCalendar.MONTH);
int dayOfMonth = myCalendar.get(Calendar.DAY_OF_MONTH);
midNightTonight = new NSTimestamp(year, month+1, dayOfMonth, 23, 59,
59, tz);
midNightYesterday = new NSTimestamp(year, month+1, dayOfMonth-1, 23,
59, 59, tz);
On Friday, March 12, 2004, at 08:51 AM, 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.