[android-developers] Re: How to store date and time in database
Knowing the policy is not an adequate solution, because the information about leap seconds just isn't there. You can add external knowledge of historical leap seconds, but you still can't tell the difference between a leap second, and one second prior to that leap second (or after, depending on your policy). And it's exactly time intervals that fail using unix time. This is what I hadn't realized; I thought Unix time actually counted seconds. But no, the POSIX committee thought it better to make the time conversion libraries slightly simpler, and have the Unix clock be discontinuous about once every year and a half. It actually jumps backwards! Which makes it useless as a general representation of time at 1 second precision. It's fine if you just want to know when your meeting is, but is a disaster if you want to know if one file was written before another. Of course, POSIX doesn't define file times with sub-second resolution, but Linux does. But there are tons of things that DO make use of timestamps, and monotonic times are absolutely essential in many applications. Your idea of making the second longer is good for computers, and I liked it at first glance -- but it would be lousy for everything else, as it would require redefinition of just about everything! The value of 'c', for example. BTW, there's no leap second this year. The last one was in 2008, so I'd guess there'll probably be one at the end of 2011. On Dec 29, 5:00 pm, DanH danhi...@ieee.org wrote: Of course, if you're adding/subtracting you need to know what your policy is not just for leap seconds but for DST -- a much more common and substantial problem. In general you shouldn't add/subtract seconds in an attempt to calculate days/months/years, but should convert to/from some sort of calendar notation, letting the conversion handle such oddities. (And one hopes that no one's relying on Android accuracy to run a nuclear reactor.) (Though actually medical devices and industrial controls are fairly happy with the Unix clock, since they mostly just want to measure time intervals, not calculate wall time accurately.) (And I've always felt that a serious mistake was made to add leap seconds, vs define the second a hair longer and subtract seconds. Handling an 61 second minute is far trickier for a computer than handling a 59 second minute.) On Dec 29, 3:00 pm, Bob Kerns r...@acm.org wrote: Sort and compare, mostly true -- but fail if you try to deal with a leap second. At least that's relatively rare. Subtract? No. Fails if a leap second falls between the two times. This is much a much more common case. In either case, your software can malfunction anew on every leap second. Do you want medical device, or industrial control, or flight navigation system, to hiccup on every leap second? Sometimes a second is an enormous error. On Dec 29, 9:05 am, DanH danhi...@ieee.org wrote: It should be pointed out that it doesn't matter (much) what time reference is used, so long as it's used consistently, and all conversion algorithms to/from the reference form understand its details. So long as a consistent reference is used dates will sort and compare correctly. On Dec 28, 9:41 pm, Bob Kerns r...@acm.org wrote: I didn't realize until now that POSIX absolutely FAILED on this. Every description I've seen of this time indicates either that it's number of seconds since January 1, 1970, or that it's UTC -- but it is, in fact, neither. ((Bangs head on keyboard at one second intervals, carefully skipping over leap seconds)). I'm torn between thanking you for pointing this out, and screaming! Both, I guess. I guess it shows how poorly people -- even people on standards committees who OUGHT to know better -- understand time. See the Sun Javadoc for the wiggle room Java allows, based on whatever imperfections the underlying OS has on this score:http://download.oracle.com/javase/6/docs/api/java/util/Date.html The Android SDK documentation, on the other hand, is pathetically silent on the matter. The Wikipedia article on Unix time indicates that there's discussion of dropping leap seconds, and letting civil time drift. I guess eventually, noon will lose whatever vestiges of meaning it has now. This has been a sore point for me for decades. Timekeeping with sufficient accuracy (i.e within seconds) for celestial navigation is one of the greatest scientific endeavors, occupying some of science's best minds over centuries, culminating in the Longitude Prize, offered in 1714 and ultimately won in 1773. The earth rotates one nautical mile at the equator every 4 seconds, so even one second of error in time contributes significant error in position. I have in my possession the 6 volumes of Sight Reduction Tables published by the US Defense Mapping Agency. 6 volumes of tables of
[android-developers] Re: How to store date and time in database
Somehow I missed seeing your first paragraph when I responded before. Your first paragraph seems to be *exactly backwards*. You appear to be mixing calendars and times. DST has no bearing on subtracting two times, any more than timezone does. In general, if you want to calculate tine intervals, subtracting seconds is the ONLY sane way to do it. Days, and thus weeks, and obviously months and years, are simply ill-defined. Seconds (and multiples thereof) are the only time representation in common use with a precise definition. (Minutes, hours, and even days only have a precise definition if defined in terms of the second; it is ambiguous whether you're referring to time or calendar intervals). DST is a *local presentation* issue. Perhaps what you're trying to get at is the special case of wanting to add 7 days, or two months to a calendar, so that, e.g. 12:30 pm on Tuesday becomes 12:30pm on the next Tuesday, regardless of leap seconds or DST changes. In that case, you do want to strictly deal with the calendar representation (ala Java's Calendar class). But that's a calendar operation, not a time operation. One certainly shouldn't confuse them, and one should not add 60*60*24*7 seconds to do a calendar operation. But if what you need to know is how much time is between last Tuesday at 12:37:38.023 and this Tuesday at 12:37:38.023, then subtraction of a TIME representation is EXACTLY the right operation. On Dec 29, 5:00 pm, DanH danhi...@ieee.org wrote: Of course, if you're adding/subtracting you need to know what your policy is not just for leap seconds but for DST -- a much more common and substantial problem. In general you shouldn't add/subtract seconds in an attempt to calculate days/months/years, but should convert to/from some sort of calendar notation, letting the conversion handle such oddities. (And one hopes that no one's relying on Android accuracy to run a nuclear reactor.) (Though actually medical devices and industrial controls are fairly happy with the Unix clock, since they mostly just want to measure time intervals, not calculate wall time accurately.) (And I've always felt that a serious mistake was made to add leap seconds, vs define the second a hair longer and subtract seconds. Handling an 61 second minute is far trickier for a computer than handling a 59 second minute.) On Dec 29, 3:00 pm, Bob Kerns r...@acm.org wrote: Sort and compare, mostly true -- but fail if you try to deal with a leap second. At least that's relatively rare. Subtract? No. Fails if a leap second falls between the two times. This is much a much more common case. In either case, your software can malfunction anew on every leap second. Do you want medical device, or industrial control, or flight navigation system, to hiccup on every leap second? Sometimes a second is an enormous error. On Dec 29, 9:05 am, DanH danhi...@ieee.org wrote: It should be pointed out that it doesn't matter (much) what time reference is used, so long as it's used consistently, and all conversion algorithms to/from the reference form understand its details. So long as a consistent reference is used dates will sort and compare correctly. On Dec 28, 9:41 pm, Bob Kerns r...@acm.org wrote: I didn't realize until now that POSIX absolutely FAILED on this. Every description I've seen of this time indicates either that it's number of seconds since January 1, 1970, or that it's UTC -- but it is, in fact, neither. ((Bangs head on keyboard at one second intervals, carefully skipping over leap seconds)). I'm torn between thanking you for pointing this out, and screaming! Both, I guess. I guess it shows how poorly people -- even people on standards committees who OUGHT to know better -- understand time. See the Sun Javadoc for the wiggle room Java allows, based on whatever imperfections the underlying OS has on this score:http://download.oracle.com/javase/6/docs/api/java/util/Date.html The Android SDK documentation, on the other hand, is pathetically silent on the matter. The Wikipedia article on Unix time indicates that there's discussion of dropping leap seconds, and letting civil time drift. I guess eventually, noon will lose whatever vestiges of meaning it has now. This has been a sore point for me for decades. Timekeeping with sufficient accuracy (i.e within seconds) for celestial navigation is one of the greatest scientific endeavors, occupying some of science's best minds over centuries, culminating in the Longitude Prize, offered in 1714 and ultimately won in 1773. The earth rotates one nautical mile at the equator every 4 seconds, so even one second of error in time contributes significant error in position. I have in my possession the 6 volumes of Sight Reduction Tables published by the US Defense Mapping Agency. 6 volumes of tables of numbers
[android-developers] Re: How to store date and time in database
It should be pointed out that it doesn't matter (much) what time reference is used, so long as it's used consistently, and all conversion algorithms to/from the reference form understand its details. So long as a consistent reference is used dates will sort and compare correctly. On Dec 28, 9:41 pm, Bob Kerns r...@acm.org wrote: I didn't realize until now that POSIX absolutely FAILED on this. Every description I've seen of this time indicates either that it's number of seconds since January 1, 1970, or that it's UTC -- but it is, in fact, neither. ((Bangs head on keyboard at one second intervals, carefully skipping over leap seconds)). I'm torn between thanking you for pointing this out, and screaming! Both, I guess. I guess it shows how poorly people -- even people on standards committees who OUGHT to know better -- understand time. See the Sun Javadoc for the wiggle room Java allows, based on whatever imperfections the underlying OS has on this score:http://download.oracle.com/javase/6/docs/api/java/util/Date.html The Android SDK documentation, on the other hand, is pathetically silent on the matter. The Wikipedia article on Unix time indicates that there's discussion of dropping leap seconds, and letting civil time drift. I guess eventually, noon will lose whatever vestiges of meaning it has now. This has been a sore point for me for decades. Timekeeping with sufficient accuracy (i.e within seconds) for celestial navigation is one of the greatest scientific endeavors, occupying some of science's best minds over centuries, culminating in the Longitude Prize, offered in 1714 and ultimately won in 1773. The earth rotates one nautical mile at the equator every 4 seconds, so even one second of error in time contributes significant error in position. I have in my possession the 6 volumes of Sight Reduction Tables published by the US Defense Mapping Agency. 6 volumes of tables of numbers for accurate calculation of spherical trigonometry with detailed attention to accuracy, carefully described procedures for calculation, down the the model of computer (IBM 1401) used to perform the calculations. And yes, I used to use them. When your personal safety, and of your crew, depends on accurate time, it gives you a different perspective on the matter! Accurate timekeeping is no less important in computer systems, where properly sequencing internal and external events is often critical -- and sometimes involves life safety. Yet generations of programmers and system administrators alike have refused to be bothered with accurate timekeeping. I guess I'll go protest by setting all my clocks to UTC. (I've used exclusively 24-hour time for almost 40 years, and am used to doing the conversion to/from UTC, so it won't bother me!) On Dec 27, 9:12 pm, Steve Allen sla29...@gmail.com wrote: On Dec 26, 11:39 pm, Kostya Vasilyev kmans...@gmail.com wrote: 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. Keep in mind that the count of milliseconds does not conform to legal nor physical elapsed time for any observer. See here for morehttp://www.ucolick.org/~sla/leapsecs/epochtime.html -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to store date and time in database
Without even considering the computational aspects of this issue, there are at least 3 definitions of noon depending on how you measure a day: http://en.wikipedia.org/wiki/Earth%27s_rotation On Dec 28, 7:41 pm, Bob Kerns r...@acm.org wrote: The Wikipedia article on Unix time indicates that there's discussion of dropping leap seconds, and letting civil time drift. I guess eventually, noon will lose whatever vestiges of meaning it has now. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: How to store date and time in database
And that's not even considering the effects of tidal friction. I love Wikipedia. -- Kostya 29.12.2010 21:46, Bret Foreman пишет: Without even considering the computational aspects of this issue, there are at least 3 definitions of noon depending on how you measure a day: http://en.wikipedia.org/wiki/Earth%27s_rotation On Dec 28, 7:41 pm, Bob Kernsr...@acm.org wrote: The Wikipedia article on Unix time indicates that there's discussion of dropping leap seconds, and letting civil time drift. I guess eventually, noon will lose whatever vestiges of meaning it has now. -- 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to store date and time in database
Sort and compare, mostly true -- but fail if you try to deal with a leap second. At least that's relatively rare. Subtract? No. Fails if a leap second falls between the two times. This is much a much more common case. In either case, your software can malfunction anew on every leap second. Do you want medical device, or industrial control, or flight navigation system, to hiccup on every leap second? Sometimes a second is an enormous error. On Dec 29, 9:05 am, DanH danhi...@ieee.org wrote: It should be pointed out that it doesn't matter (much) what time reference is used, so long as it's used consistently, and all conversion algorithms to/from the reference form understand its details. So long as a consistent reference is used dates will sort and compare correctly. On Dec 28, 9:41 pm, Bob Kerns r...@acm.org wrote: I didn't realize until now that POSIX absolutely FAILED on this. Every description I've seen of this time indicates either that it's number of seconds since January 1, 1970, or that it's UTC -- but it is, in fact, neither. ((Bangs head on keyboard at one second intervals, carefully skipping over leap seconds)). I'm torn between thanking you for pointing this out, and screaming! Both, I guess. I guess it shows how poorly people -- even people on standards committees who OUGHT to know better -- understand time. See the Sun Javadoc for the wiggle room Java allows, based on whatever imperfections the underlying OS has on this score:http://download.oracle.com/javase/6/docs/api/java/util/Date.html The Android SDK documentation, on the other hand, is pathetically silent on the matter. The Wikipedia article on Unix time indicates that there's discussion of dropping leap seconds, and letting civil time drift. I guess eventually, noon will lose whatever vestiges of meaning it has now. This has been a sore point for me for decades. Timekeeping with sufficient accuracy (i.e within seconds) for celestial navigation is one of the greatest scientific endeavors, occupying some of science's best minds over centuries, culminating in the Longitude Prize, offered in 1714 and ultimately won in 1773. The earth rotates one nautical mile at the equator every 4 seconds, so even one second of error in time contributes significant error in position. I have in my possession the 6 volumes of Sight Reduction Tables published by the US Defense Mapping Agency. 6 volumes of tables of numbers for accurate calculation of spherical trigonometry with detailed attention to accuracy, carefully described procedures for calculation, down the the model of computer (IBM 1401) used to perform the calculations. And yes, I used to use them. When your personal safety, and of your crew, depends on accurate time, it gives you a different perspective on the matter! Accurate timekeeping is no less important in computer systems, where properly sequencing internal and external events is often critical -- and sometimes involves life safety. Yet generations of programmers and system administrators alike have refused to be bothered with accurate timekeeping. I guess I'll go protest by setting all my clocks to UTC. (I've used exclusively 24-hour time for almost 40 years, and am used to doing the conversion to/from UTC, so it won't bother me!) On Dec 27, 9:12 pm, Steve Allen sla29...@gmail.com wrote: On Dec 26, 11:39 pm, Kostya Vasilyev kmans...@gmail.com wrote: 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. Keep in mind that the count of milliseconds does not conform to legal nor physical elapsed time for any observer. See here for morehttp://www.ucolick.org/~sla/leapsecs/epochtime.html -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to store date and time in database
Of course, if you're adding/subtracting you need to know what your policy is not just for leap seconds but for DST -- a much more common and substantial problem. In general you shouldn't add/subtract seconds in an attempt to calculate days/months/years, but should convert to/from some sort of calendar notation, letting the conversion handle such oddities. (And one hopes that no one's relying on Android accuracy to run a nuclear reactor.) (Though actually medical devices and industrial controls are fairly happy with the Unix clock, since they mostly just want to measure time intervals, not calculate wall time accurately.) (And I've always felt that a serious mistake was made to add leap seconds, vs define the second a hair longer and subtract seconds. Handling an 61 second minute is far trickier for a computer than handling a 59 second minute.) On Dec 29, 3:00 pm, Bob Kerns r...@acm.org wrote: Sort and compare, mostly true -- but fail if you try to deal with a leap second. At least that's relatively rare. Subtract? No. Fails if a leap second falls between the two times. This is much a much more common case. In either case, your software can malfunction anew on every leap second. Do you want medical device, or industrial control, or flight navigation system, to hiccup on every leap second? Sometimes a second is an enormous error. On Dec 29, 9:05 am, DanH danhi...@ieee.org wrote: It should be pointed out that it doesn't matter (much) what time reference is used, so long as it's used consistently, and all conversion algorithms to/from the reference form understand its details. So long as a consistent reference is used dates will sort and compare correctly. On Dec 28, 9:41 pm, Bob Kerns r...@acm.org wrote: I didn't realize until now that POSIX absolutely FAILED on this. Every description I've seen of this time indicates either that it's number of seconds since January 1, 1970, or that it's UTC -- but it is, in fact, neither. ((Bangs head on keyboard at one second intervals, carefully skipping over leap seconds)). I'm torn between thanking you for pointing this out, and screaming! Both, I guess. I guess it shows how poorly people -- even people on standards committees who OUGHT to know better -- understand time. See the Sun Javadoc for the wiggle room Java allows, based on whatever imperfections the underlying OS has on this score:http://download.oracle.com/javase/6/docs/api/java/util/Date.html The Android SDK documentation, on the other hand, is pathetically silent on the matter. The Wikipedia article on Unix time indicates that there's discussion of dropping leap seconds, and letting civil time drift. I guess eventually, noon will lose whatever vestiges of meaning it has now. This has been a sore point for me for decades. Timekeeping with sufficient accuracy (i.e within seconds) for celestial navigation is one of the greatest scientific endeavors, occupying some of science's best minds over centuries, culminating in the Longitude Prize, offered in 1714 and ultimately won in 1773. The earth rotates one nautical mile at the equator every 4 seconds, so even one second of error in time contributes significant error in position. I have in my possession the 6 volumes of Sight Reduction Tables published by the US Defense Mapping Agency. 6 volumes of tables of numbers for accurate calculation of spherical trigonometry with detailed attention to accuracy, carefully described procedures for calculation, down the the model of computer (IBM 1401) used to perform the calculations. And yes, I used to use them. When your personal safety, and of your crew, depends on accurate time, it gives you a different perspective on the matter! Accurate timekeeping is no less important in computer systems, where properly sequencing internal and external events is often critical -- and sometimes involves life safety. Yet generations of programmers and system administrators alike have refused to be bothered with accurate timekeeping. I guess I'll go protest by setting all my clocks to UTC. (I've used exclusively 24-hour time for almost 40 years, and am used to doing the conversion to/from UTC, so it won't bother me!) On Dec 27, 9:12 pm, Steve Allen sla29...@gmail.com wrote: On Dec 26, 11:39 pm, Kostya Vasilyev kmans...@gmail.com wrote: 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. Keep in mind that the count of milliseconds does not conform to legal nor physical elapsed time for any observer. See here for morehttp://www.ucolick.org/~sla/leapsecs/epochtime.html -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email
[android-developers] Re: How to store date and time in database
On Dec 26, 11:39 pm, Kostya Vasilyev kmans...@gmail.com wrote: 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. Keep in mind that the count of milliseconds does not conform to legal nor physical elapsed time for any observer. See here for more http://www.ucolick.org/~sla/leapsecs/epochtime.html -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to store date and time in database
For that to sort by date and time properly, you'll have to change the text format! On Dec 26, 10:29 pm, Nandlal Viranni nandlal.phys...@gmail.com wrote: On Mon, Dec 27, 2010 at 11:51 AM, pramod.deore deore.pramo...@gmail.comwrote: 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? Its very simple.. create SQLITE database for this. Use attached java file for creating database. Change file according your requirement.. It will automatically creates database in your project.. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.comandroid-developers%2Bunsubs cr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en DBAdapter.java 8KViewDownload -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to store date and time in database
I didn't realize until now that POSIX absolutely FAILED on this. Every description I've seen of this time indicates either that it's number of seconds since January 1, 1970, or that it's UTC -- but it is, in fact, neither. ((Bangs head on keyboard at one second intervals, carefully skipping over leap seconds)). I'm torn between thanking you for pointing this out, and screaming! Both, I guess. I guess it shows how poorly people -- even people on standards committees who OUGHT to know better -- understand time. See the Sun Javadoc for the wiggle room Java allows, based on whatever imperfections the underlying OS has on this score: http://download.oracle.com/javase/6/docs/api/java/util/Date.html The Android SDK documentation, on the other hand, is pathetically silent on the matter. The Wikipedia article on Unix time indicates that there's discussion of dropping leap seconds, and letting civil time drift. I guess eventually, noon will lose whatever vestiges of meaning it has now. This has been a sore point for me for decades. Timekeeping with sufficient accuracy (i.e within seconds) for celestial navigation is one of the greatest scientific endeavors, occupying some of science's best minds over centuries, culminating in the Longitude Prize, offered in 1714 and ultimately won in 1773. The earth rotates one nautical mile at the equator every 4 seconds, so even one second of error in time contributes significant error in position. I have in my possession the 6 volumes of Sight Reduction Tables published by the US Defense Mapping Agency. 6 volumes of tables of numbers for accurate calculation of spherical trigonometry with detailed attention to accuracy, carefully described procedures for calculation, down the the model of computer (IBM 1401) used to perform the calculations. And yes, I used to use them. When your personal safety, and of your crew, depends on accurate time, it gives you a different perspective on the matter! Accurate timekeeping is no less important in computer systems, where properly sequencing internal and external events is often critical -- and sometimes involves life safety. Yet generations of programmers and system administrators alike have refused to be bothered with accurate timekeeping. I guess I'll go protest by setting all my clocks to UTC. (I've used exclusively 24-hour time for almost 40 years, and am used to doing the conversion to/from UTC, so it won't bother me!) On Dec 27, 9:12 pm, Steve Allen sla29...@gmail.com wrote: On Dec 26, 11:39 pm, Kostya Vasilyev kmans...@gmail.com wrote: 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. Keep in mind that the count of milliseconds does not conform to legal nor physical elapsed time for any observer. See here for morehttp://www.ucolick.org/~sla/leapsecs/epochtime.html -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to store date and time in database
Be very, very, VERY careful about storing date and time information in a textual format. There are boundary conditions, timezone issues, leap-year issues, skipped-leap-year-issues, leap seconds, and finally, localization issues, which can all reach out and bite you in ways you may not consider. Generally, the best option is to not worry about all this, and (as Kostya rightly points out) use the system-provided utilities for interpreting dates (if you receive them as text), or work entirely with longs and never deal with text at all except when displaying to the user (with proper consideration of timezone and localization). Otherwise, you're taking on a considerable coding and testing burden AND a good deal of risk. The only downside is it makes examining stored date/time data much more difficult, but you can write a little calculator to do this. Java and Javascript date formats (and pretty much everybody else) use seconds since 00:00 January 1, 1970 UTC as their representation, so you can make yourself (or probably find pre-made) a little web page that converts them for you. On Dec 26, 11:06 pm, Kristopher Micinski krismicin...@gmail.com wrote: 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 deore.pramo...@gmail.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to store date and time in database
I do agree with this approach :-) On 27 Dic, 08:39, Kostya Vasilyev kmans...@gmail.com 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.deoredeore.pramo...@gmail.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to store date and time in database
Thanks Bob and Federico. On Dec 27, 4:59 pm, Federico Paolinelli fedep...@gmail.com wrote: I do agree with this approach :-) On 27 Dic, 08:39, Kostya Vasilyev kmans...@gmail.com 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.deoredeore.pramo...@gmail.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to store date and time in database
Ok, Now I have stored date in miliseconds format. from this I can get year, month and date(I can also get time from this). But how to store time? Because there are 2 buttons for user to select using first button user select the date on which he wants to on particular switch and second button for the time to on the switch. Should I store this time in normal int format? On Dec 27, 5:11 pm, pramod.deore deore.pramo...@gmail.com wrote: Thanks Bob and Federico. On Dec 27, 4:59 pm, Federico Paolinelli fedep...@gmail.com wrote: I do agree with this approach :-) On 27 Dic, 08:39, Kostya Vasilyev kmans...@gmail.com 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.deoredeore.pramo...@gmail.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to store date and time in database
Store it any way you want. If you want to do selection by date I'd favor long integer (seconds since 1970), unless you need sub-second resolution. But supposedly SQLite can sort out (and select by) a wide variety of date formats, as described in the article someone referenced. On Dec 27, 12:21 am, pramod.deore deore.pramo...@gmail.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to store date and time in database
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 kmans...@gmail.com 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.deoredeore.pramo...@gmail.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to store date and time in database
(Though the SQLite long int representation of date is in seconds, not milliseconds.) On Dec 27, 1:39 am, Kostya Vasilyev kmans...@gmail.com 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.deoredeore.pramo...@gmail.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to store date and time in database
Well, you can store time as date-time modulo 24 hours -- fits easily in 32 bits. Otherwise, probably some sort of hours/minutes/seconds triplet (or just hours/minutes). On Dec 27, 7:17 am, pramod.deore deore.pramo...@gmail.com wrote: Ok, Now I have stored date in miliseconds format. from this I can get year, month and date(I can also get time from this). But how to store time? Because there are 2 buttons for user to select using first button user select the date on which he wants to on particular switch and second button for the time to on the switch. Should I store this time in normal int format? On Dec 27, 5:11 pm, pramod.deore deore.pramo...@gmail.com wrote: Thanks Bob and Federico. On Dec 27, 4:59 pm, Federico Paolinelli fedep...@gmail.com wrote: I do agree with this approach :-) On 27 Dic, 08:39, Kostya Vasilyev kmans...@gmail.com 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.deoredeore.pramo...@gmail.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to store date and time in database
Wha On Dec 27, 6:14 am, DanH danhi...@ieee.org wrote: Well, you can store time as date-time modulo 24 hours -- fits easily in 32 bits. Otherwise, probably some sort of hours/minutes/seconds triplet (or just hours/minutes). -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to store date and time in database
(Ignore the previous garbage post; it posted while I was typing; who knows why. Mouse was nowhere near the Send button). I would recommend storing the date+time in milliseconds as a single field, just as Java's Date class does. This makes sorting work 100% properly -- a benefit I forgot to mention in my previous message. My previous message also said seconds since 1 January 1970, when it should have said milliseconds. That is, it's counting seconds, in a fixed-point format with millisecond resolution. If you need femptosecond resolution, add that as an additional field. :=) On Dec 27, 6:14 am, DanH danhi...@ieee.org wrote: Well, you can store time as date-time modulo 24 hours -- fits easily in 32 bits. Otherwise, probably some sort of hours/minutes/seconds triplet (or just hours/minutes). -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: How to store date and time in database
milliseconds from midnight jan 1 1970 UTC to midnight dec 27 2010 UTC plus miliseconds from midnight dec 27 2010 UTC to 15:57 27 dec 2010 UTC -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to store date and time in database
Here's a handy reference article: http://en.wikipedia.org/wiki/Unix_time -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: How to store date and time in database
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 danhi...@ieee.org 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 kmans...@gmail.com 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.deoredeore.pramo...@gmail.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: How to store date and time in database
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 -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, DanHdanhi...@ieee.org 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 Vasilyevkmans...@gmail.com 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.deoredeore.pramo...@gmail.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to store date and time in database
One nice thing about the string representation is that you can read it. This is VERY useful for debugging. In theory SQLite will allow different representations to interoperate seamlessly, but it's not something I would want to rely on. So, you pays your money and you takes your choice. On Dec 27, 12:29 pm, Kristopher Micinski krismicin...@gmail.com wrote: 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 danhi...@ieee.org 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 kmans...@gmail.com 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.deoredeore.pramo...@gmail.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to store date and time in database
Thanks Kristopher for your reply. On Dec 27, 12:06 pm, Kristopher Micinski krismicin...@gmail.com wrote: 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 deore.pramo...@gmail.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to store date and time in database
Store it simply as a long. On Dec 27, 2:21 pm, pramod.deore deore.pramo...@gmail.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to store date and time in database
Thanks Kostya I think this one is better. Thanks once again. On Dec 27, 12:39 pm, Kostya Vasilyev kmans...@gmail.com 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.deoredeore.pramo...@gmail.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en