views:

95

answers:

3

Hi, I am exporting a date value from sqlite and placing it into an email. The date appears like this 279498721.322872

I am using Objective C in an Iphone App. Does anyone know how to make this export out as a regular date whether it is all number like 2009-02-10 or anything legible?

+1  A: 
echo date("Y-m-d",time(279498721.322872));
Treby
I wish I could use this :)
Leland usher
+2  A: 

Well, if you take the number 279498721.322872 and throw it into an NSDate object using +dateWithTimeIntervalSinceReferenceDate, you get (here in the MDT timezone): 2009-11-09 15:32:01 -0700, which was just under 4 hours ago. If that's the time you're expecting, then formatting it is as simple as using an NSDateFormatter.

However, the thing to notice is that sqlite (by default) stores dates as textual representations (unless you specify differently in the sql statement). So the real question here is "where are you getting that number from?"

Dave DeLong
Dave, thanks, so far... NSString *tempString = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"EEEE, MMMM d, yyyy"]; NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:279498721]; NSString *formattedDateString = [dateFormatter stringFromDate:date]; NSLog(@"formattedDateString: %@", formattedDateString);when I try to place tempString where the 2794.... number is at the system errors:"incompatible type of argument.Any thoughts.Thx
Leland usher
@Leland - yeah. 2974... is a number (a primitive). You can't pass in an object there.
Dave DeLong
A: 

Thanks for the responses. The answer came from my Guru Alex Cone. He told me to use the following:

NSTimeInterval tempInterval = (NSTimeInterval)sqlite3_column_double(statement, 4);

The tempInterval variable can then be loaded into the the NSDate method.

Leland usher