php date time supporting date values before year 1970

“I need to store birthdate of my customers where it can fall before year 1970.” Php function date(), strtotime() uses UNIX timestamp which supports year 1970 to 2038. To work with date values beyond that, we need to use php datetime class which is available on after php version 5.2.0 (datetime manual). Create a date before 1970: $dt = new DateTime(); $dt->setDate(1945, 8, 8); // August 8 1945, end of world war 2 If you need to store time as well: //public DateTime DateTime::setTime ( int $hour , int $minute [, int $second = 0 ] ) //seconds argument is optional $dt->setTime(8,0,45); // 8:00:45 am To print the date: echo¬†$dt->format('Y-m-d H:i:s'); //outputs //1945-08-08 08:00:45 For list of date format to use, refer to http://php.net/manual/en/function.date.php. Hope it helps....

PHP Formatting Date

To display current date we use the date function in PHP. <?php //string date ( string $format [, int $timestamp ] ) echo date("Y-m-d H:i"); ?> Result: 2021-02-25 12:50 The date() function requires 1 parameter which is the string format to format the current date time to our liking. Refer to the php date documentation for more details on the formatting string. The 2nd optional parameter which takes in an integer value representing the date time comes in handly where in some situation, we need to display specific dates. We use mktime() function to create the specific date time. <?php //int mktime ([ int $hour = date("H") [, int $minute = date("i") [, int $second = date("s") [, int $month = date("n") [, int $day = date("j") [, int $year = date("Y") [, int $is_dst = -1 ]]]]]]] ) //mktime(8,0,0,10,20,2010) creates a date time specific to 20th October 2010, 8:00 am echo date("Y-m-d H:i",mktime(8,0,0,10,20,2010)); ?> Result: 2010-10-20...