• 12

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 187


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 187
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Unix timestamp before 1970 (even before 1700), using PHP

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!

You can use DateTime.


$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.

  • 15
Reply Report
      • 2
    • DateTime is the future. +1. Note that you need PHP 5.3 to enjoy some of the DateTime goodness (Intervals, CreateFromFormat and such). If in doubt, the manual will tell you the required version
      • 1
    • DateTime cannot go before 1901 in all case. $date = new DateTime('1869-01-01 07:00:00'); echo $date->format('U'); << This works. $date->setTimestamp(-3187208524); echo $date->format('Y-m-d H:i:s'); << This does not work!
    • @vee works here (5.5.9). Maybe you're using a 32-bit build of PHP? Try passing the timestamp as a float instead (-3187208524.).