What happened on Dec 31 1969 at 7:00 PM - php

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

Related

In PHP, how to get UTC date for calendars that include Day Light Savings (DLS)

I'm not sure if the gmdate() function in PHP captures the Day Light Savings reality of the world. For example this code:
<?php
echo "<pre>";
echo "Current timezone: ", date_default_timezone_get(), "\n";
$future_date = 'Nov 03, 2019 03:30 PM EDT';
$future_UTC = gmdate('M d, Y h:i A T', strtotime($future_date));
echo "
New York Date: $future_date
GMT/UTC time: $future_UTC
";
?>
Prints out this:
Current timezone: UTC
New York Date: Nov 03, 2019 03:30 PM EDT
GMT/UTC time: Nov 03, 2019 07:30 PM GMT
This is technically incorrect, because on Nov 3 at 2pm, the DLS will switch and the time in GMT/UTC will actually be 08:30 PM, instead of the erroneous 07:30 PM that PHP is showing (based on today's DLS).
Is there any way to automatically get the right time for future dates?
There are many errors here, starting with the title of your question:
how to get UTC date for calendars that include Day Light Savings (DLS)
UTC is well-defined, and has no daylight savings time. If you're in a different timezone, and in a locality that has daylight savings time, then you're not in UTC anymore. So, the question is nonsensical to begin with.
$future_date = 'Nov 03, 2019 03:30 PM EDT';
EDT means "Eastern Daylight Time", so in this case you're forcing a particular interpretation, regardless of date. You'll note that if you change it to EST (Eastern Standard Time), you'll get a different result.
You probably want America/New_York instead of EDT. See also: https://www.php.net/manual/en/timezones.php
This is technically incorrect, because on Nov 3 at 2pm, the DLS will switch
No. 2:00 AM.
Is there any way to automatically get the right time for future dates?
Stop feeding PHP broken data and ambiguously formatted dates. We have date/time standards for a reason, such as ISO8601. Date/time is a complicated thing. Computers can't read minds, and don't know what you intended when you gave it the wrong date for a specific type of timezone with daylight savings time.

PHP and timezone

I am using strtotime() to get a timestamp from a date and time string. I will be running strtotime() during the summer (daylight savings) to give me a timestamp of a winter date (non-daylight savings).
In the winter, I will need to convert my timestamp to a readable date using date() -- will it be the same date/time I put into strtotime() during the summer?
On each one of my pages, I am setting my timezone by date_default_timezone_set with my city.
So, running this during the summer (daylight savings):
date_default_timezone_set('America/Los_Angeles');
echo strtotime("Dec 1 2014 8:00 am");
Gives me a certain timestamp 1417449600.
Will running this during the winter (non-daylight savings) return 8:00am as I need it to do?
date_default_timezone_set('America/Los_Angeles');
echo date("g:ia",1417449600);
Yes. If the timezone you set is doesn't explicitly say whether it's standard or daylight-savings time, it automatically determines the state of DST from the time that you give it and the rules for when the timezone switches into and out of DST.
Yes. A UNIX timestamp such as 1417449600 represents a completely, globally, universally unique point in time, independent of fussy timezone notation. There's only one "December 1st 2014 8 am in Los Angeles", which is the same point in time as "December 1st 2014 17:00 CET" and a number of other local notations across the world. The UNIX timestamp 1417449600 expresses that point in time, regardless of whatever your wall clock says exactly.
When you format this unique point in time back to a more human readable format using date(), it figures out what exactly the time must be formatted at based on the set timezone. It won't change based on what the time or DST settings are now.

Is this a bug in PHP's gmstrftime() function?

I'm having a problem with PHP's gmstrftime() function.
Please look:
<?
$ts[]=1348573985; // '2012-09-25 13:53:05' (date returned from mysql's from_unixtime() function)
$ts[]=1233958620; // '2009-02-06 23:17:00' (date returned from mysql's from_unixtime() function)
foreach($ts as $t) {
echo $t." => ".gmstrftime( "%d %B %Y - %H:%M", $t )."\n";
}
?>
Output will be:
1348573985 => 25 September 2012 - 11:53
1233958620 => 06 February 2009 - 22:17
As you can see, the first timestamp is 2 hours off (from mysql's output), which is normal because of timezone settings. But the second one is only 1 hour off but I did not change the timezone between the two gmstrftime() call's??
Is this a bug in PHP's gmstrftime() function, or anything else?
From the manual for gmstrftime:
Behaves the same as strftime() except that the time returned is Greenwich Mean Time (GMT).
Greenwich Mean Time is the same all year around. This is different from the local time in the UK, which is set as GMT in winter, but "British Summer Time" (GMT+1, i.e. one hour ahead of GMT) in the summer. The same happens in Western Europe, which is GMT+1 in winter, but GMT+2 in summer.
Your MySQL database is presumably configured for local European time, so when converting a Unix timestamp that occurs during the summer, it adds an extra hour to line up with the Summer Time adjustment.
In my opinion, the best policy is to set all your systems to use 'UTC' (basically the same as GMT) and then convert to a local timezone "at the last minute". You could standardise on some other timezone, but UTC acts as a good baseline for debugging.

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.

php Timestamp working logic

what is exactly happing when creating a Unix Timestamp from a given date.
I want the step by step method to create timestamp. (not using php built in functions).
EDIT: What is the specialty of this date :) January 1st 1970 00:00 h UTC
January 1st 1970 00:00 h UTC is the date of the Epoch :
The "epoch" then serves as a reference
point from which time is measured.
Time measurement units are counted
from the epoch so that the date and
time of events can be specified
unambiguously.
In computing, this date is the Epoch for UNIX time : UNIX timestamps (as used by PHP) are actually the number of seconds since that Epoch.
This means that, to create a timestamp, you have to count how many seconds have passed since the 1st January 1970.
You just have to count the seconds that elapsed from January 1st 1970 00:00 h UTC until now (not counting leap seconds)!

Categories