<?php $day = '1'; $month = '3'; $year = '1994'; $born = date(mktime(0, 0, 0, $month, $day, $year)); echo date('dnY', $born); ?> 

I 762458400 and 1.3.1994

 <?php $day = '17'; $month = '1'; $year = '1962'; $born = date(mktime(0, 0, 0, $month, $day, $year)); echo date('dnY', $born); ?> 

I -251078400 and 16.12.1977
should be 17.1.1962

Is there another solution?

    1 answer 1

    It is not entirely clear what exactly you want, because this:

     17.1.1962 

    It turns out elementary:

     echo "$day.$month.$year"; 

    You can look towards DateTime , for example:

     $date = DateTime::createFromFormat('m/d/Y', "$month/$day/$year"); echo $date->format('F j, Y'); // Janyary 17, 1962 

    But you need to be prepared for the fact that:

     echo $date->getTimestamp(); 

    -251050001 . In fact, this is the reason for all the troubles: EMNIP, only Windows does not know how to work with negative timestamp values, and for this OS you have to make crutches. Others are fine with this:

     $ cat ./d.php && uname && ./d.php #!/usr/bin/php <?php $day = '17'; $month = '1'; $year = '1962'; $tstamp = mktime(0, 0, 0, $month, $day, $year); $born = date( $tstamp ); echo "$tstamp <=> ".date('dnY', $born); Linux -251089200 <=> 17.1.1962 
    • Thanks DateTime helped! - KYRAN