473,473 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Portable general timestamp format, not 2038-limited

I have a requirement to store timestamps in a database. Simple enough
you might think but finding a suitably general format is not easy. The
specifics are

1) subsecond resolution - milliseconds or, preferably, more detailed
2) not bounded by Unix timestamp 2038 limit
3) readable in Java
4) writable portably in Perl which seems to mean that 64-bit values
are out
5) readable and writable in Python
6) storable in a free database - Postgresql/MySQL

The formats provided by the two database systems are such as 8-byte or
12-byte values which, even if I could get Perl to work with I guess it
would be messy. Keeping to 32-bit values should give me portability
and be easy enough to work with without obscuring the program logic.
Since 32 bits of microseconds is less than 50 days I have to store two
32-bit values. How to split them? The option I favour at the moment is
to split days and parts of days like this:

a) store, as a 32-bit number, days since a virtual year zero (there is
no year zero in common era time <http://en.wikipedia.org/wiki/
Common_Era>). This allows over five million years plus and minus.
Still not completely general, I know.
b) store parts of days as another 32-bit value. Its range would have
to go to 86401 seconds - the number of seconds in a leap day. This
means each 'tick' would be around 21 microseconds. For regularity I
could make the ticks 25 microseconds so there would be 40,000 in a
second and 3,456,000,000 in a day; and, finally, the counter could
tick about 5 hours into the next day if not caught.

Any thoughts on a better way to do this? (Please reply-all. Thanks).

--
James

Jun 22 '07
67 4711
On 5 Jul, 02:53, greg <g...@cosc.canterbury.ac.nzwrote:
James Harris wrote:
With that the time would range to +/- 9000
quintillion years (18 digits)

Use the Big Bang as the epoch, and you won't have
to worry about negative timestamps.
Good idea if only they didn't keep shifting the femtosecond on which
it happened...... :-)
Jul 5 '07 #51
On 5 Jul, 08:46, Dennis Lee Bieber <wlfr...@ix.netcom.comwrote:
On Wed, 04 Jul 2007 22:12:46 -0400, Roy Smith <r...@panix.comdeclaimed
the following in comp.lang.python:
Astronomers use Julian Date (http://en.wikipedia.org/wiki/Julian_date) for
calculations like this. It's a widely used format and highly portable.
I'm sure there are libraries to deal with it in all the languages you
mention (and more). Ask on sci.astro for more information.

<playing devils advocateBut do you also need to account for
Besselian or Julian centuries (Astronomy used to use B1900 as a
computational epoch, but now uses J2000. A Julian century is 36525 days,
Besselian century was 36524.22 days.
Whew! It was for reasons such as this that I suggested treating a day
(i.e. a /nominal/ 24-hour period) as the primary unit. The Gregorian
switch to Julian, for example, missed out a bunch of days to adjust
the calendars of Christendom but they had to be whole numbers of days.
In terms of real people (about the level I need) once a dividing line
has been chosen between one day and the next it becomes a reference
point.

Incidentally I have chosen to store /average/ values in the
application so if the sample period is 10 seconds and the count
increases by 45 I will store 4.5. This is plottable directly and I
could even allow an 11 second sample when a leap second is added (if I
needed that detail).

Is your Julian century a bit long, on average, 2000, 2400, 2800 etc
having 28 days in Feb?

Jul 5 '07 #52
[A complimentary Cc of this posting was sent to
James Harris
<ja************@googlemail.com>], who wrote in article <11**********************@m36g2000hse.googlegroups .com>:
On 5 Jul, 02:53, greg <g...@cosc.canterbury.ac.nzwrote:
James Harris wrote:
With that the time would range to +/- 9000
quintillion years (18 digits)
Use the Big Bang as the epoch, and you won't have
to worry about negative timestamps.
In pedantic mode: negative timestamps make sense with Big Bang as the
epoch as well. (AFAIU, the current way of thinking is that it was
"just too hot" before the big bang, it is not that "there was
nothing".)

Hope this helps,
Ilya
Jul 5 '07 #53
James Harris wrote :
I have a requirement to store timestamps in a database. Simple enough
you might think but finding a suitably general format is not easy. The
specifics are

2) not bounded by Unix timestamp 2038 limit
I use the Java Calendar class for storing dates, which as I understand
it, uses a long to store the date/time/milliseconds.

In my application I use the date 9999.12.31 23:59:59.000 to store a
blank date. Calendar has no problem storing that date, and returning
the correct year, month, day, hour, minute, and second.

Note: Since I am using the year 9999 as a "magic number", some of you
may think that I am repeating the Y2K problem. Hey, if my application
is still being used in the year 9998 I am not being paid nearly
enough...

--
Wojtek :-)
Jul 5 '07 #54
En Thu, 05 Jul 2007 17:57:32 -0300, Wojtek <no*****@a.comescribió:
Note: Since I am using the year 9999 as a "magic number", some of you
may think that I am repeating the Y2K problem. Hey, if my application
is still being used in the year 9998 I am not being paid nearly
enough...
I would not say the code itself, but some design decisions may survive for
a long time. Like the railroad inter-rail distance, which even for the
newest trains, remains the same as used by Stephenson in England two
centuries ago - and he choose the same width as used by common horse carts
at the time. (Some people goes beyond that and say it was the same width
as used in the Roman empire but this may be just a practical coincidence,
no causality being involved).

--
Gabriel Genellina

Jul 9 '07 #55
Gabriel Genellina wrote:
En Thu, 05 Jul 2007 17:57:32 -0300, Wojtek <no*****@a.comescribió:
>Note: Since I am using the year 9999 as a "magic number", some of you
may think that I am repeating the Y2K problem. Hey, if my application
is still being used in the year 9998 I am not being paid nearly
enough...

I would not say the code itself, but some design decisions may survive for
a long time. Like the railroad inter-rail distance, which even for the
newest trains, remains the same as used by Stephenson in England two
centuries ago - and he choose the same width as used by common horse carts
at the time. (Some people goes beyond that and say it was the same width
as used in the Roman empire but this may be just a practical coincidence,
no causality being involved).
Brunel, of course, being an original, built his system with a wider
inter-rail gap, and passengers commented on the smoother ride they got.
But standardization wars aren't new, and IKB lost that one.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Jul 9 '07 #56
Ilya Zakharevich wrote:
In pedantic mode: negative timestamps make sense with Big Bang as the
epoch as well. (AFAIU, the current way of thinking is that it was
"just too hot" before the big bang, it is not that "there was
nothing".)
If Stephen Hawking is right, the shape of the universe
is such that there isn't any time "before" the big bang
at all. It's like asking what's north of the North Pole.

Of course, this may have been replaced with some other
equally bizarre idea by now...

Another thought: If the cosmologists ever decide if
and when the Big Crunch is going to happen, we may be
able to figure out once and for all how many bits we
need in the timestamp.

--
Greg
Jul 10 '07 #57
Ilya Zakharevich wrote:
[A complimentary Cc of this posting was sent to
greg
<gr**@cosc.canterbury.ac.nz>], who wrote in article <5f*************@mid.individual.net>:
>Ilya Zakharevich wrote:
>>In pedantic mode: negative timestamps make sense with Big Bang as the
epoch as well. (AFAIU, the current way of thinking is that it was
"just too hot" before the big bang, it is not that "there was
nothing".)
If Stephen Hawking is right, the shape of the universe
is such that there isn't any time "before" the big bang
at all. It's like asking what's north of the North Pole.

I do not remember any statement like this - even from 70s... Could
you provide a reference? There were conjectures about "initial
singularity", but I do not recollect them related to SH.
Its in "A Short History of Time". Sorry I can't quote chapter or page,
but a friend borrowed my copy and lent me Dawkins "Climbing Mount
Improbable" before vanishing, never to be seen since. Not an equal
exchange: I preferred ASHOT to CMI.
--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
Jul 10 '07 #58
(Absolutely off topic!)

En Mon, 09 Jul 2007 15:50:58 -0300, Steve Holden <st***@holdenweb.com>
escribió:
Brunel, of course, being an original, built his system with a wider
inter-rail gap, and passengers commented on the smoother ride they got.
But standardization wars aren't new, and IKB lost that one.
And later the Great Western Railway got the most beautiful locomotives of
all times!

I don't know the current status, but some years ago here in Argentina
around 40% of the railroad system were using "wide gauge" = 1676mm, wider
than standard but not as wide as the original GWR.
Now most of the passenger lines are defunct and cargo lines trend to use
narrow gauge = 1000mm so the proportion may be much smaller now.

--
Gabriel Genellina

Jul 11 '07 #59
[A complimentary Cc of this posting was sent to
Martin Gregorie
<ma****@see.sig.for.address>], who wrote in article <u1************@zoogz.gregorie.org>:
If Stephen Hawking is right, the shape of the universe
is such that there isn't any time "before" the big bang
at all. It's like asking what's north of the North Pole.
I do not remember any statement like this - even from 70s... Could
you provide a reference? There were conjectures about "initial
singularity", but I do not recollect them related to SH.
Its in "A Short History of Time". Sorry I can't quote chapter or page,
but a friend borrowed my copy and lent me Dawkins "Climbing Mount
Improbable" before vanishing, never to be seen since. Not an equal
exchange: I preferred ASHOT to CMI.
I would prefer a reference to a peer-reviewed paper. ;-)

Thanks,
Ilya
Jul 11 '07 #60
Ilya Zakharevich wrote:
[A complimentary Cc of this posting was sent to
Martin Gregorie
<ma****@see.sig.for.address>], who wrote in article <u1************@zoogz.gregorie.org>:
>Its in "A Short History of Time". Sorry I can't quote chapter or page,
but a friend borrowed my copy and lent me Dawkins "Climbing Mount
Improbable" before vanishing, never to be seen since. Not an equal
exchange: I preferred ASHOT to CMI.
Oops - I should have written "A Brief History of Time". It was the first
edition, so I don't know if it was altered/edited out of later versions.
I would prefer a reference to a peer-reviewed paper. ;-)
Sure, but I don't think you'll find one. It was in a descriptive, rather
than rigorous, passage. But then, the book famously had only one
equation in it.
--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
Jul 11 '07 #61
"greg" <gr**@cosc.c...ry.ac.nzwrote:
>
Another thought: If the cosmologists ever decide if
and when the Big Crunch is going to happen, we may be
able to figure out once and for all how many bits we
need in the timestamp.
Unless of course, its all an oscillation - bang, crunch, bang, crunch,
as the cosmic engine ticks over...

But of course, cycles other than our own are kind of unreachable.

- Hendrik
Jul 11 '07 #62
[A complimentary Cc of this posting was sent to
Martin Gregorie
<ma****@see.sig.for.address>], who wrote in article <qk************@zoogz.gregorie.org>:
Its in "A Short History of Time". Sorry I can't quote chapter or page,
but a friend borrowed my copy and lent me Dawkins "Climbing Mount
Improbable" before vanishing, never to be seen since. Not an equal
exchange: I preferred ASHOT to CMI.
Oops - I should have written "A Brief History of Time". It was the first
edition, so I don't know if it was altered/edited out of later versions.
I would prefer a reference to a peer-reviewed paper. ;-)
Sure, but I don't think you'll find one. It was in a descriptive, rather
than rigorous, passage. But then, the book famously had only one
equation in it.
[I've heard about this book.]

My point is that attributing something to SH due to it appearing in
ABHoT is like attributing it to you since it was mentioned in your
post...

Hope this helps,
Ilya
Jul 11 '07 #63
On Jun 22, 1:33 pm, James Harris <james.harri...@googlemail.com>
wrote:
I have a requirement to store timestamps in a database. Simple enough
you might think but finding a suitably general format is not easy. The
specifics are

1) subsecond resolution - milliseconds or, preferably, more detailed
2) not bounded by Unix timestamp 2038 limit
3) readable in Java
4) writable portably in Perl which seems to mean that 64-bit values
are out
5) readable and writable in Python
6) storable in a free database - Postgresql/MySQL

The formats provided by the two database systems are such as 8-byte or
12-byte values which, even if I could get Perl to work with I guess it
would be messy. Keeping to 32-bit values should give me portability
and be easy enough to work with without obscuring the program logic.
Since 32 bits of microseconds is less than 50 days I have to store two
32-bit values. How to split them? The option I favour at the moment is
to split days and parts of days like this:

a) store, as a 32-bit number, days since a virtual year zero (there is
no year zero in common era time <http://en.wikipedia.org/wiki/
Common_Era>). This allows over five million years plus and minus.
Still not completely general, I know.
b) store parts of days as another 32-bit value. Its range would have
to go to 86401 seconds - the number of seconds in a leap day. This
means each 'tick' would be around 21 microseconds. For regularity I
could make the ticks 25 microseconds so there would be 40,000 in a
second and 3,456,000,000 in a day; and, finally, the counter could
tick about 5 hours into the next day if not caught.

Any thoughts on a better way to do this? (Please reply-all. Thanks).
The best timestamp of which I am aware is microseconds since the
calendarical convergence back in 4713 BCE. This is the format used on
the old Tandem systems. Tandem chose to begin days at midnight, so
with some small tweaking, you can calculate the Julian day (by adding
12 hours) also, but you can choose to begin them at noon (as the
official Julian day does).

It is easily represented in 64 bits and won't overflow until well past
10000 CE. It also has the advantage of making for easy easy time
arithmetic and for reasonable conversion into any native format with
resolution no better than about 10 nanoseconds. You have to be
careful, if your resolution is better than that (you might overflow a
64-bit number if you try to go to your native format by multiplying
first), but it is quite useful.

The magic number for Unix-32 format is 210866760000000000 (or that
divided by 1000 or 1000000 depending upon which way you go)

Jul 11 '07 #64
Ilya Zakharevich wrote:
My point is that attributing something to SH due to it appearing in
ABHoT is like attributing it to you since it was mentioned in your
post...
OK, so who should it be attributed to?
--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
Jul 12 '07 #65
[A complimentary Cc of this posting was sent to
Martin Gregorie
<ma****@see.sig.for.address>], who wrote in article <qj************@zoogz.gregorie.org>:
Ilya Zakharevich wrote:
My point is that attributing something to SH due to it appearing in
ABHoT is like attributing it to you since it was mentioned in your
post...
OK, so who should it be attributed to?
*This* was my question; and with kitchentop book, one cannot expect to
find such an answer. If interested, Wiki looks like a good place to
look it up.

Given how obsolete this conjecture is (it contradicts the now known
data about uniformity of background radiation), I have no interest in
looking it up. :-(

Sorry,
Ilya
Jul 12 '07 #66
Ilya Zakharevich <no**********@ilyaz.orgwrites:
*This* was my question; and with kitchentop book, one cannot expect
to find such an answer. If interested, Wiki looks like a good place
to look it up.
I don't know what Wiki[0] has to do with it, but just to check:

<URL:http://c2.com/cgi/wiki?WhatIsNorthOfTheNorthPole>

Nope, can't find any existing page about it.
[0] Left unqualified, referring to a site named "Wiki" refers to *the*
Wiki, at <URL:http://c2.com/cgi/wiki>. If you mean some other
subsequent Wiki site, you'll need to be more specific.

--
\ "Consider the daffodil. And while you're doing that, I'll be |
`\ over here, looking through your stuff." -- Jack Handey |
_o__) |
Ben Finney
Jul 12 '07 #67
Lew
Ben Finney wrote:
[0] Left unqualified, referring to a site named "Wiki" refers to *the*
Wiki, at <URL:http://c2.com/cgi/wiki>. If you mean some other
subsequent Wiki site, you'll need to be more specific.
I'm betting they meant
<http://en.wikipedia.org/wiki/Main_Page>

or one of its non-English siblings.

--
Lew
Jul 12 '07 #68

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ben | last post by:
I would like to use php to query a database and retrieve a unix timestamp. The problem is that mysql is storing the data in the date format and not a timestamp. I am sure that I can amend my...
7
by: Joshua Beall | last post by:
Hi All, Any thoughts on the easiest way to translate a MySQL timestamp (which looks like 20040422090941) to the datetime format (which looks like 2004-04-22 09:09:41). This is just to make it...
4
by: RT | last post by:
If anyone can help that would be great. I¹m trying to format a timestamp from my MySQL table (sessions) Here¹s the code I¹m using: <?php echo date('D,n-j-y h:i:s...
13
by: perplexed | last post by:
How do you convert a user inputted date to a unix timestamp before insterting it into your database? I have a form, with a textfield for a date that the user inputs in the format mm-dd-yyyy and...
0
by: zion1459 | last post by:
Hi, having a problem using timestamps... all timestamps in the database is are made correctly. It's when I try to convert them it goes wrong. now the weird part is, if I just do a date("D M j...
0
by: James Foreman | last post by:
Looking at the documentation on EXPORT, when exporting a date column it will automatically use yyyymmdd. One could choose to use ISO format, but unfortunately the client I'm exporting to can't...
9
by: pankaj_wolfhunter | last post by:
Hi, I need some clearance on the following questions: 1) Does LOAD command updates indexes defined for a table? 2) Is REPLACE option in the LOAD command a logged operation? Help will be...
4
by: mghale | last post by:
I have a question that I'm hoping has an easy answer. I'm working in DB2 V8.2 on AIX 5.3 I have a timestamp column (i.e. 4/26/2006 1:02:42.000000 PM) that I want to return in a report from...
6
by: marc | last post by:
hi im trying to convert Date() into a unix timestamp so i can stick the result into a mysql db, please help!
8
by: kanwal | last post by:
Hi, I have millions of records in my xxxxx table in mysql. And I have a column of time in which I have stored the timestamp using php time() function. Now I wanna write an SQL query to fetch...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.