note 105053 deleted from function.strtotime by derick
| From: | derick@php.net | Date: | Sun, 14 Dec 2014 11:39:05 +0000 |
| Subject: | note 105053 deleted from function.strtotime by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-201184@lists.php.net to get a copy of this message | ||
Note Submitter: ei7024 at wayne dot edu
----
This is the solution to the problems with date below 1970. Below code help the date to show up in
format such as MM/DD/YYYY. It can be tailored to fit any format.
This works if the database stores the dates in "DATE" format.
<?php
$query = "SELECT emp_fn,emp_ln, emp_dob FROM requests WHERE id=$id;";
$result = mysql_query($query,$DBConn);
$row = mysql_fetch_array($result);
//TESTING BELOW 1970 Date of Birth
$dobcheck = strtotime($row['emp_dob']);
//NOTE: echo $dobcheck on your system to see if you get negative values for date below 1970
if ($dobcheck <= 0)
{
$date = $row['emp_dob'];
$date = explode('-', $date);
$Y = $date[0];
$M = $date[1];
$D = $date[2];
$dobshow = $M."/".$D."/".$Y; //echos mm/dd/YYYY format for dates below
1970.
} else {
$dobshow = date("m/d/Y",strtotime($row['emp_dob']));
}
//ENDTESTING
?>