What is the last Unix time? - php

What is the last Unix time in decimal? I'm going to set it as the expiration date of cookies (using PHP). Is it possible to cause problem?

Sunday, December 4, 292,277,026,596 AD (on 64-bit systems)

For a 32-bit time_t value, you will overflow in mid to late January 2038. Specifically about 3:14 AM UTC on January 19 (actually somewhere between 3:14 and 3:15 but that should be close enough for you).
The maximum value is 231-1 or 2,147,483,647.

2147483647

Related

PHP getTimestamp not working when adding 100 years [duplicate]

I just found out, running a calendar script, that timestamps in PHP has a limit to 2038. What does it really mean? Why is it 2038 instead of 2050 or 2039? Why a limit if timestamps just count seconds from a given date (1970)?
The limit is imposed by the 4 byte signed integers that most C libraries use for representing that count. Quick math (assumes 365 day years, not exactly correct):
2147483648 seconds ~ 68.1 years
This also implies a lower limit of ~1900. Some libraries have started to introduce 64 bit epoch counts, but they are few and far between for the moment.
The maximum value of a signed 32-bit integer is 2,147,483,647. If you add +1 to that, you get -2,147,483,647. 2,147,483,647 seconds from 01-01-1970 00:00:00 is January 19, 2038. If you add one more second, you get a date somewhere in 1902.
due to the limit of INT datatype on 32 bit machine
http://php.net/manual/en/function.mktime.php
From php.net :
"The maximum possible date accepted by mktime() and gmmktime() is dependent on the current location time zone.
For example, the 32-bit timestamp overflow occurs at 2038-01-19T03:14:08+0000Z. But if you're in a UTC -0500 time zone (such as EST in North America), the maximum accepted time before overflow (for older PHP versions on Windows) is 2038-01-18T22:14:07-0500Z, regardless of whether you're passing it to mktime() or gmmktime()."
my guess is that it is stored in a fixed number of bits, which means a limit on how big the timestamp can get. We could do some math to figure it out exactly.

How can i fix strotime for the year 1800

I have a little trouble with strtotime, I have a date 18 july 1868 and when I record in the database, I make $date = strtotime (18-07-1868). But when I appear it, I dated ('Y-m-d', $date) but it does not show me 18-07-1868 but 13-12-1901.
How can I fix this problem?
Thx,
From the manual:
The valid range of a timestamp is typically from Fri, 13 Dec 1901
20:45:54 UTC to Tue, 19 Jan 2038 03:14:07 UTC.
(These are the dates that correspond to the minimum and maximum values for a 32-bit signed
integer.)
Additionally, not all platforms support negative timestamps,
therefore your date range may be limited to no earlier than the Unix
epoch. This means that e.g. dates prior to Jan 1, 1970 will not work
on Windows, some Linux distributions, and a few other operating
systems. PHP 5.1.0 and newer versions overcome this limitation though.
So it depends on the platform you're running it on. It needs to be 64 bit to exceed the range stated in the manual.
You are not putting a string (single quote or double quote) in strtotime() function...
Try This...
$x = strtotime('18-07-1868');
echo date('Y-m-d', $x);

Why do timestamps have a limit to 2038?

I just found out, running a calendar script, that timestamps in PHP has a limit to 2038. What does it really mean? Why is it 2038 instead of 2050 or 2039? Why a limit if timestamps just count seconds from a given date (1970)?
The limit is imposed by the 4 byte signed integers that most C libraries use for representing that count. Quick math (assumes 365 day years, not exactly correct):
2147483648 seconds ~ 68.1 years
This also implies a lower limit of ~1900. Some libraries have started to introduce 64 bit epoch counts, but they are few and far between for the moment.
The maximum value of a signed 32-bit integer is 2,147,483,647. If you add +1 to that, you get -2,147,483,647. 2,147,483,647 seconds from 01-01-1970 00:00:00 is January 19, 2038. If you add one more second, you get a date somewhere in 1902.
due to the limit of INT datatype on 32 bit machine
http://php.net/manual/en/function.mktime.php
From php.net :
"The maximum possible date accepted by mktime() and gmmktime() is dependent on the current location time zone.
For example, the 32-bit timestamp overflow occurs at 2038-01-19T03:14:08+0000Z. But if you're in a UTC -0500 time zone (such as EST in North America), the maximum accepted time before overflow (for older PHP versions on Windows) is 2038-01-18T22:14:07-0500Z, regardless of whether you're passing it to mktime() or gmmktime()."
my guess is that it is stored in a fixed number of bits, which means a limit on how big the timestamp can get. We could do some math to figure it out exactly.

why strotime returns negative value in php?

I am using strtotime to convert a date to a unixtime stamp.
Year, date and day comes as different values to code and I am using the below code to produce the timestamp.
$year = '1961';
$month = '2';
$day = '15';
$date = $year."-".$month."-".$day;
echo strtotime($date);
The above code prints : -27648000 for me. If the year is above 1970 it prints out positive results. I am still learning with the timestamp, if any one can help me out. The main aim is to convert a date to unix timestamp.
The questions is why it gives negative results, Am I coding it bad!? I am also tried mktime, but still the same result.
Thanks,
Tanmay
It's to do with the Unix Epoch.
See: date() and time()
The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer). However, before PHP 5.1.0 this range was limited from 01-01-1970 to 19-01-2038 on some systems
That's the expected behavior.
strtotime returns a UNIX timestamp, the number of seconds since Jan 1 1970 (not considering leap seconds). For dates before that, it will return a negative number.
Unix time starts at the Unix epoch which is Midnight on Jan 1, 1970. So any date before that will result in a negative value being returned.
This is a Unix timestamp. The Unix/PHP base date is January 1, 1970 at 00:00 UST, and the timestamp is measured in seconds. If negative, it is the number of seconds before the base date; if positive, the number of seconds after
I am still learning with the timestamp,
google unix timestamp -> http://en.wikipedia.org/wiki/Unix_time
defined as the number of seconds elapsed since midnight proleptic Coordinated Universal Time (UTC) of
January 1, 1970
http://en.wikipedia.org/wiki/Unix_time
Unix time, or POSIX time, is a system for describing points in time, defined as the number of seconds elapsed since midnight proleptic Coordinated Universal Time (UTC) of January 1, 1970, not counting leap seconds. It is used widely, not only in Unix-like operating systems, but also in many other computing systems and file formats. It is neither a linear representation of time nor a true representation of UTC (though it is frequently mistaken for both), as the times it represents are UTC but do not represent standard UTC leap seconds (e.g. December 31, 1998 23:59:60)...
Times before 1/1/1970 are negative values as they occured before the start of UTC.

What happened on Dec 31 1969 at 7:00 PM

Every time in PHP when I make a variable such as this one:
$date = strtotime($row['date']);
$date = date("M d Y \a\\t g:i A", $date); // Mmm dd YYYY at h:mm PM/AM
and somehow row['date'] happens to be 0, the date Dec 31 1969 at 7:00 PM is displayed on the screen? Google does not tell me much, I was wondering if this date had any significances.
The Unix epoch is the time 00:00:00 UTC on 1 January 1970. This is the reference point for all time stamps. When you use PHP's date/time functions, you're always working with the number of seconds since the epoch. Time 0 is the epoch, and you (or your web server) must be on the east coast of the US, which is 5 hours behind UTC time.
I find it funny that not a single response here attempted to answer your actual question, which was (if I can paraphrase) "What is the significance of the actual date of Unix epoch time"?
I'm not an expert on the subject but basically, as I understand it, the concept of epoch time was invented in 1971. The programmers chose the arbitrary date of January 1, 1971 GMT to be epoch time. This was partly due to the fact that older computers couldn't handle large numbers so the date had to be in the recent past. Afterwards, epoch time was adjusted to be Jan 1, 1970 so as to be a nice, round number.
So basically, nothing "happened" on that date. It was an arbitrary date chosen based on the original time of the work being done.
Unix timestamps are measured in "time since the Unix Epoch", which is Midnight GMT at the end of Dec. 31 1969 (a.k.a. 00:00 GMT Jan 1 1970). Since you appear to be on Eastern Standard Time, which is GMT-5, you get 7pm Dec. 31st 1969 for a unix timestamp value of 0.
Let me guess: you live on the east coast of the USA?
PHP, like many other systems uses the Unix epoch to measure time, i.e. a value of 0 represents January 1, 1970, midnight UTC - which is the same as Dec 31 1969 at 7:00 PM Eastern Standard Time.
One format in which date objects are stored is the time in seconds that have elapsed from an arbitrary start time. Asking for a formatted version of "0" is like asking for that arbitrary start time. I don't remember why that date was chosen, but I'm sure Wikipedia does. See the article on Unix time below.
Read about Unix Time

Categories