Vivek
Vivek

Reputation: 4260

Sqlite convert not supported date to timestamp in android

I have stored a date in sqlite database in this yyyy-MM-dd'T'HH:mm:ss.SSSZ format. Example 2019-12-11T14:30:00.000+0000

I need to migrate database to convert this date to timestamp while migrating to Room. As this date format is not supported in sqlite I can't use sqlite functions to convert date to timestamp :(

How should I do it?

Upvotes: 0

Views: 103

Answers (1)

forpas
forpas

Reputation: 164069

With strftime():

strftime(
  '%s', 
  substr('2019-12-11T14:30:00.000+0000', 1, 23)
)

will return the timestamp in seconds.
See the demo.
Result:

1576074600

Upvotes: 1

Related Questions