It just all depends on the database.
SQLite docs specifically says this:
http://www.sqlite.org/datatype3.html
SQLite does not have a storage class set aside for storing dates
and/or times. Instead, the built-in Date And Time Functions of SQLite
are capable of storing dates and times as TEXT, REAL, or INTEGER values:
Note that SQLite's date/text conversions use YYYY-MM-DD HH:MM:SS.SSS
format and not the usual human readable locale-dependent format (except
for some countries). This is for data portability and selection / sorting.
"Real" SQL databases often have rich date / time data types. The
database is then aware that a particular column represents a date and/or
time value, and can have richer functionality (like date arithmetic, etc).
But since this group is about Android development, the database in
question is (typically) SQLite.
-- Kostya
27.12.2010 21:29, Kristopher Micinski пишет:
Yes,
This is why I included a link to the original SQLite reference in the
links I previously provided :-).
I agree with the long / string representation, but it's all just
representation, each has its advantages / disadvantages, though for
sorting and selection, this might be nice. I'm not an advanced SQL
user, but maybe a string format would provide some niceties with
respect to selection as well, however you could probably do the same
thing easily enough by working with some date / long conversions in
java then selecting in SQL.
kris
On Mon, Dec 27, 2010 at 9:07 AM, DanH<[email protected]> wrote:
It should be pointed out that long integer is one of the date formats
supported by SQLite.
On Dec 27, 1:39 am, Kostya Vasilyev<[email protected]> wrote:
Kris& Pramod,
With all due respect, there is a much easier way.
Java date/time stamps are internally represented by "long" values, the
value being the number of milliseconds since Jan. 1, 1970 GMT.
SQLite natively supports long (64-bit) interger values (use INTEGER data
type).
So, for storing date/time stamp, call "long milliseconds =
Date.getTime()" and store the long integer value in the database.
When retrieving, get the long integer from the database, then construct
"new Date(long milliseconds)".
This has two advantages:
- No text parsing or formatting necessary, smaller chance of bugs
- Ability to sort or select before / after a certain date/time value
when doing SELECT
Hope this helps.
-- Kostya
27.12.2010 10:06, Kristopher Micinski пишет:
http://sberka.blogspot.com/2009/07/date-time-sqlite-and-android.html
That blog post should point you in the right direction.
What you may really want to know is how SQLite handles date and time.
From what I've encountered there is no "native" date/time handling in
SQLite, but you can simply store dates / times in a textual
representation. The following articles may help give some insight:
http://stackoverflow.com/questions/4248064/delphi-sqlite-date-time-fo...
http://www.sqlite.org/lang_datefunc.html
Typically what you will do is create some database implemented via a
content provider or just database handler (see the many, many
tutorials on how to do this) and create a table for storing your
relevant information. For example, I have a "contents" table, where
one of the columns is the date an article was published. Now the only
thing you have to figure out is the marshaling.
Thanks,
Kris Micinski
On Mon, Dec 27, 2010 at 1:21 AM, pramod.deore<[email protected]>
wrote:
Hi everyone,
In my application I have 2 buttons one for DatePickerand
one for Timepicker. Date piker gives me date in this format -
12-27-2010 and time in - 11:48. Now I want to create table to store
these values. How to store date and time in android database?
Thanks.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--
Kostya Vasilyev -- WiFi Manager + pretty widget --http://kmansoft.wordpress.com
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en