Reputation: 11161
how can i work with dates before 01.01.1970?
i need to get first day of the month for dates from year 1700.
how can i achieve that?
thank you in advance!
Upvotes: 8
Views: 5598
Reputation: 133159
If the year is <1970 or the value is negative, the relationship is undefined.
-- The Open Group, Single Unix Specification, Base definitions (4: General concepts)
As you can see, it's not defined how Unix timestamps before 1970 would map to dates. It is only defined for later dates.
If you want to go to dates before 1970, you need to always work with actual dates, like ISO dates (2008-12-31T23:59:59
). You can use DateTime
class to represent any date you can think of but ever created it from a Unix timestamp or convert it to a Unix timestamp if the year is before 1970 as that will simply yield undefined results.
Upvotes: 0
Reputation: 97835
You can use DateTime
.
Example:
<?php
$d = new DateTime("1780-06-01");
echo $d->format("l"); //Thursday
You should, however, consider that the Gregorian Calendar was adopted in different instants throughout the world.
Upvotes: 15
Reputation: 301015
Try using the Zend Date classes, or the older PEAR Date class
Upvotes: 0