Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Date calculation, NSTimestamp, and PostgreSQL



I'm creating an EOQualifier to perform a fetch against a PostgreSQL db. I
calculate the time one year ago today and place it in an NSTimestamp
dateOneYearAgo. NSTimestamp is the java value class in the EOModel for the
dateTime field.

When I try to perform the fetch PostgreSQL chokes because the value of the
dateOneYearAgo NSTimestamp is "2003-06-30 18:08:39 Etc/GMT", and PostgreSQL
expects timestamps like this: "2003-06-30 18:08:39 GMT", or this:
"2004-06-29 14:11:20.288774".

So I need a way to format dateOneYearAgo that PostgreSQL will accept.

Any ideas on the best way to accomplish this? (see code below).


// create Calendar obj and calc date one year ago
Calendar workingCalendar = Calendar.getInstance();
workingCalendar.add( Calendar.DAY_OF_MONTH, -365 );

// convert to NSTimestamp
NSTimestamp dateOneYearAgo = new NSTimestamp(workingCalendar.getTime());

// create qualifier and perform fetch
qual = EOQualifier.qualifierWithQualifierFormat("custNo = " + key + "and
dateTime > '"  + dateOneYearAgo + "'", null);
logInfo = ec.objectsWithFetchSpecification(logFetchSpec);


-- 
Randall Perry
sysTame

Xserve Web Hosting/Co-location
Website Design/Development
WebObjects Hosting
Mac Consulting/Sales

http://www.systame.com/
_______________________________________________
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.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.