timestamp

Using a SQLite date/time field with Flutter and Dart

As a brief note, SQLite doesn’t have date/time (datetime) fields, so when you want to use a datetime field with Flutter (and Dart), you have to do something else.

My choice was to store my datetime data as a SQLite INTEGER field. I did this so I can query and sort that field easily myself. (The benefit of storing a datetime field as a TEXT field is that you can read it easier, but I think an INTEGER field is a little easier to work with, though YMMV.)

A Python script to read RSS feeds (and much more)

With the caveats that (a) I don’t know much about Python, (b) I don’t want to learn that much about it right now, and (c) I’m not concerned with performance at the moment, the following Python script does the following:

How to default a MySQL date (timestamp) field to now alvin October 10, 2012 - 4:25pm

MySQL DATE syntax FAQ: How do I set a MySQL DATE field to default to "now", i.e., the current time?

Setting the date to "now"

Unfortunately you can't default a MySQL DATE field to "now", but you can get the "now" behavior with a MySQL TIMESTAMP field. The syntax to create a MySQL TIMESTAMP "now" field is:

Creating a PHP date in the format for a SQL Timestamp insert

PHP date/time FAQ: How do I create a date in the proper format to insert a SQL Timestamp field into a SQL database?

First off, you may not need to create a date in PHP like this. If you're using plain old PHP and a database like MySQL, you can use the SQL 'now()' function to insert data into a SQL timestamp field, like this:

MySQL Error 1293 - Incorrect table definition (TIMESTAMP)

MySQL Error 1293 FAQ: Help, I'm getting a MySQL incorrect table definition error message related to a TIMESTAMP column. How do I get past it?

If you ever get this MySQL Error 1293 (like I just did):

ERROR 1293 (HY000): Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

fear not, it may not be too bad. Let's take a look.

Update MySQL timestamp on update

MySQL timestamp FAQ: How can I update a MySQL TIMESTAMP field when I issue an update for a MySQL database table?

MySQL has some crazy rules about how timestamp fields can be created, but one nice "timestamp update" syntax you can use looks like this, assuming that you're declaring a timestamp field named last_updated:

Java Timestamp example: How to create a “current timestamp” (i.e., now)

Java date/time FAQ: When working with the Timestamp class, how do I create a “Java current timestamp”? For instance, how do I create a JDBC Timestamp object to represent the “current time” (“now”)?

Solution

You can create a “current time” JDBC Timestamp in just a few lines of code, using the Java Calendar class and a java.util.Date instance, as shown in this example code:

Java Date/Calendar example: How to get today’s date (now)

Java Date/Calendar FAQ: How do I get an instance of today's date with Java? (A Java Date to represent "now").

Although you're strongly encouraged not to get today's date using the Date class, like this:

Date today = new Date();

you can still get today's date in Java using one line of code with the Java Calendar class, like this:

JDBC Timestamp - How to select a Java Timestamp field from a database timestamp column

Here's a JDBC Timestamp example that shows how to read a Java Timestamp field from a database timestamp column (a MySQL Timestamp field) in a SQL SELECT statement. I pulled this source code out of a real-world Java application, so I'll break it into small steps, and hopefully it will make sense.

The MySQL timestamp field definition

My Java application uses a MySQL database, including one table named commands that has a MySQL Timestamp field I need to read. The SQL definition for this MySQL table is shown below: