Android SQLite tip - default datetime to now
Android SQLite FAQ: How do I default a SQLite datetime field to the current time, i.e., now?
Just use the SQLite "default current_timestamp" syntax, as shown in bold here:
create table projects ( _id integer primary key autoincrement, name text not null, description text, date_created datetime default current_timestamp );
If you create your table like that, then insert a sample record into the table like this:
insert into projects (project_type, name, description) values ('APPLICATION', 'Amazon - Purchasing', 'The description here');
then query the table like this:
select * from projects;
you'll see that the default datetime was set to 'now':
1|Amazon - Purchasing|The description here|2012-02-05 20:22:55
Reporting live from sunny Boulder, Colorado, I hope this Android SQLite "default date time" example has been helpful.
Recent blog posts
- Business Analyst: How to write accurate software requirements
- Business Analyst: A simple secret to running a great meeting
- One thing a business analyst should ask about any requirement
- Business Analysts and Use Case quality: Questions to ask yourself when writing a Use Case
- The three things a Business Analyst should think about during meetings
- Testing web applications Selenium with Scala 3 and ScalaTest
- Scala Cookbook 2021: A best-selling new release in OOP and FP
- Salar Rahmanian's newsletter (and Functional Programming, Simplified)
- Our “Back To Now” app: Now available on iOS and Android
- An Android location “Fused Location Provider API” example