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.
Valley Programming is currently a one-person business, owned and operated by Alvin Alexander. If you’re interested in anything you read here, feel free to contact me at “al” at (“@”) this website name (“valleyprogramming.com”), or at the phone number shown below. I’m just getting back to business here in November, 2021, and eventually I’ll get a contact form set up here, but until then, I hope that works.
Recent blog posts
- Free: Introduction To Functional Programming video training course
- The #1 functional programming (and computer programming) book
- The User Story Mapping Workshop process
- Alvin Alexander, Certified Scrum Product Owner (CSPO)
- Alvin Alexander is now a Certified ScrumMaster (CSM)
- Our “Back To Then” app (for iOS and Android)
- A Docker cheat sheet
- Pushing a Scala 3 JAR/Docker file to Google Cloud Run
- Reading a CSV File Into a Spark RDD (Scala Cookbook recipe)
- Reading a File Into a Spark RDD (Scala Cookbook recipe)