I have dates that are being stored in a database by core data. I then am using php to print out this date information but the date is coming out wrong.
When I store Aug 2, 2009 in core data it comes out in the php as Fri, August 4, 1978. How do I fix the conversion?
I'm guessing a bit here, but the limited evidence fits the hypothesis...
NSDate has an absolute reference date of 1 Jan 2001 (GMT).
PHP time() uses the Unix Epoch date of 1 Jan 1970 (GMT).
It looks like you have an offset of 31 years - or rather 978307200 seconds.
(NSTimeInterval) delta = [[NSDate dateWithTimeIntervalSinceReferenceDate:0] timeIntervalSince1970];
Solution would be to either create your dates in Cocoa with the reference date of 1970, or to add/subtract the offset in Cocoa or PHP.
James
Related
In my code users post date in content. Which is may be in different formats the format which is used in majority auto sets in MySQL date time field format i.e. yyyy-mm-dd hh:mm:ss. My problem is most of them have typo mistakes or different formats which my code doesn't pick correctly and it returns date something like this 1970-01-01 05:00:00. I am in deep from this issue. Is there any function that auto corrects the date time even if there is a typo mistake in it and if time is not available it auto adds the time to it?
Here are some examples of different formats I get
30 September 2017 | 09 31 AM
29 September 2017 | 02:30 PM
27/07/2016 | 08:20 PM
19/09/2017| 01:32 PM
14-July-2017 03:31 PM
September 5 2017
April 7 2016 04:55 PM
Here is my current PHP code
$get_date = ""; //Date in text form
$show_dated = strtotime(str_replace('|', '', $get_date);
$get_date = date("Y-m-d H:i:s", $show_dated);
echo $get_date;
Try using date_parse() instead of strtotime(). I did this for a while, and it functioned better. Ultimately my solution was to build a custom parser based on the confused mess of user inputs. I eyeballed 2000 entries to develop a 'gold standard' set of results, and then fine-tuned an algorithm to match until it performed 100% correctly.
Bootstrap time picker gives me Date in this format:
Mon Mar 16 2015 00:00:00 GMT-0500 (Central Daylight Time)
I would like to use it as a Date object in PHP.
I am attempting to use it like:
date("Y-m-d H:i:s" , strtotime("Mon Mar 16 2015 00:00:00 GMT-0500 (Central Daylight Time)"));
But that results in:
1969-12-31 18:00:00
Which I understand to be pretty close to EPOCH.
I'm thinking I'm either using the wrong function, or I formatted date() wrong.
I am using the TimePicker from here.
strtotime only works on certain formats of which can be found here http://php.net/manual/en/datetime.formats.php
Mar 16 2015 00:00:00 GMT-0500
The above portion should return the right time value for you. Either change the way that the picker is outputting the date, without knowing which picker I will assume its this one http://bootstrap-datepicker.readthedocs.org/en/latest/options.html#format or do some string manipulation on the current date format from the picker (the first option would be simpler and easier to read).
I have a table in SQL Server 2005, and it has column period (datetime).
The value of the column period is 8/7/2009 12:00:00 AM, when I query using php script it give me output Aug 7 2009 12:00AM.
Why it's not 8/7/2009 12:00:00 AM ???
Thank you
Your question reads like this:
The value of the column period is
{ a date, year 2009 month August day 7th at 12:00 AM}
When I query using php script it give me output "Aug 7 2009 12:00AM", i.e. one representation of the date.
Why it's not "8/7/2009 12:00:00 AM", i.e. another representation of the date
A datetime represents a point in time. It is a specific concept. You are comparing two separate representations of the datetime, or in other words, two ways of formatting the datetime value as a textual string.
The issue you are trying to solve is then, "How do I format a datetime as a string in PHP"? For which the answer would be to refer to the date_format (aka DateTime::format) function
To wit, the display specifier for 8/7/2009 12:00:00 AM is n/j/Y h:i:s A.
First off, this is not a question about how to fix a problem because my date is outputting 1969.
This is a question about why time does not exist before 1970 or after 2038 when using date().
I've tried seaching SO and Google but all that turns up is people getting errors when using date() incorrectly, resulting in the familiar output of December 31, 1969 5:00 pm
Does anyone know why it can't go before 1970? Should we stop using date() since it will be unusable after 2038? What's the history on this? What's the work around for working with dates outside of this range?
It's 2038 problem
and look, I'm in year 1653
This is explained on the PHP manual page for date():
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).
The fact that you're getting December 31, 1969 means that you're likely supplying an odd timestamp parameter to date(), resulting in a date that isn't what you expect. Like #Mitch Wheat said in his comment, this relates to Unix time since it is relative from January 1, 1970.
Compare the number 2^31 and the number of seconds between the two date.
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