Date calculation, NSTimestamp, and PostgreSQL
Date calculation, NSTimestamp, and PostgreSQL
- Subject: Date calculation, NSTimestamp, and PostgreSQL
- From: Randall Perry <email@hidden>
- Date: Tue, 29 Jun 2004 14:21:23 -0400
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.