| 
	
 | 
 Posted by Brandon on 01/22/07 08:13 
> >There's an "underlying" storage for dates?  I wasn't aware that PHP had 
> >a true date type for a timestamp for "lie under." 
> 
> It doesn't need a *TRUE* date type, it just needs some way to store 
> dates (and for the date library functions to use as input and 
> output).  And a 32-bit integer is pretty lame nowadays.  And that 
> seems to be what PHP uses for the date library functions (on 32-bit 
> machines, anyway). 
 
All I wanted to know was whether I was missing a set of functions that 
deal with a true date type (something that stores the parts of a date 
separately and takes timezones into account) or if integer timestamps 
were all that PHP provides functions for right now. 
 
By the way, integer timestamps are definitely not 32-bits.  If they 
were, timestamps would have overflowed in less than two months.  Any 
place I've seen them in a typed language (C/C++, Java, etc.), they have 
been 64-bit "long" integers. 
 
> >Timestamps are just 
> >integers. 
> 
> This is not true in general, unless you're saying that "all bits 
> is just bits" and trinary is impossible.  For example, in MySQL, a 
> timestamp has pieces year, month, day, hour, minute, and second. 
> In MS-DOS, a file timestamp also had these fields, but the number 
> of seconds was missing a bit so only even seconds were possible, 
> and the range of years were very limited.  And some programs just 
> store dates as strings, with or without a time zone. 
 
It sounds like you might be using the word "timestamp" in a much more 
general way but a true timestamp is, by definition, just a long integer 
representing the time since Jan 1, 1970 Greenwich Mean Time.  What you 
are describing are other representations of a date/time, which is 
exactly what I am after. 
 
In fact, since you mentioned MySQL, the "timestamp" type in MySQL 4.1+ 
is ACTUALLY a "datetime" object, which is a more complex representation 
of a date and time including a timezone.  Prior to version 4.1, MySQL's 
timestamp type was actually a true POSIX timestamp - all you got back 
from a query was a number. 
 
> >I was just hoping that PHP would have something 
> >built in for storing dates in a format other than timestamps. 
> 
> I consider "something built in for storing dates in a format" to 
> *BE* a timestamp by definition, even if it's not a POSIX timestamp. 
 
So are you saying that there IS an alternative in PHP?  Because so far, 
I haven't found one.  Just look at the documentation at PHP.net and 
look at the example I gave. 
 
$timeStr = "2005-04-06 15:43:34"; 
$time = strtotime($timeStr); 
print date('Y-m-d \a\t H:i', $time)."\n"; 
 
$timeStr is just a plain old string and strtotime() parses it into a 
POSIX timestamp, which is then passed around to wherever it needs to go 
and most of PHP's functions take UNIX timestamps.
 
  
Navigation:
[Reply to this message] 
 |