Question: I'm trying to store today's date in a sqlite table as a string in a 24-hour time format regardless of the user's locale. Because NSDate honours the user's locale, this code returns different results depending on the user's location:

```
NSLog(@"The date is %@", [NSDate date]);

```

If their locale is set to the United Kingdom, where 24-hour time is the default, the above returns
'The date is 2009-09-05 11:17:35', whereas if they're in the United States, where 12-hour time is the default, it returns 'The date is 2009-09-05 11:17:35 AM'.

Is there a way to automatically detect and convert 12-hour time to 24-hour time before committing it to the database? I'm using SQLite Persistent Objects, so I need to provide the date as an NSDate and not NSString.

Answer: 
In my previous answer I thought you were having issues with SQLite Persistent Objects, but that's not the case. I think you've simply misunderstood what the following code is actually doing:

```
NSLog(@"The date is %@", [NSDate date]);

```

The reason why you're getting different log output under different locales is *not* because of NSDate, it's because of the NSDateFormatter being used under the hood to insert the string representation of `[NSDate date]` into your log string using `%@`. In fact, NSDate has no concept of "12-hour" or "24-hour" locales -- it's just a representation of a point in time.

Locales come into play when you turn your NSDate into a string, such as in an NSLog statement or as part of an SQL query string. When you want to do that, you should specify your own explicit formatter, like so:

```
NSDateFormatter *formatter = [[NSDateFormatter alloc] initWithDateFormat:@"yyyy-MM-dd HH:mm:ss" allowNaturalLanguage:NO];
NSLog(@"The date is %s", [formatter stringFromDate:[NSDate date]]);
[formatter release];

```

Using the above, you should get identical strings regardless of the users' locale settings.

As for your SQL queries, am I right in thinking that you're also using `%@` to insert the date into the query string? If so, you should do something like this instead:

```
NSString* criteriaTemplate = @"WHERE date(due) BETWEEN date(%d) AND date('now', 'localtime')";
NSString* criteria = [NSString stringWithFormat: criteriaTemplate, [myNSDate timeIntervalSince1970]];
NSArray* todayTasks = [Task findByCriteria:criteria];

```

Hope this helps.
This looks like a bug in SQLite Persistent Objects. The library takes your NSDate instance and serialises it as a string in the format `@"yyyy-MM-dd HH:mm:ss.SSSS"`, which means that the timezone information is actually being thrown out. When the date string is converted back into an NSDate, the timezone is assumed to be the local time zone. This works only in the case that all your NSDate instances are in the local time zone.

The easiest way of fixing this is to patch the `NSDate(SqlPersistence)` category defined by SQLite Persistent Objects in `NSDate-SQLitePersistence.m` to include the timezone in the format string (e.g. `@"yyyy-MM-dd HH:mm:ss.SSSS Z"`) during serialisation and deserialisation. However, the proper fix would be to serialise the NSDate using the a DATETIME column rather than a char-based column. 

When you're displaying the dates in your UI, you can then use your own `NSDateFormatter` to define your own string date format.