note 105053 added to function.strtotime

From: Date: Mon, 25 Jul 2011 13:57:52 +0000
Subject: note 105053 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-181851@lists.php.net to get a copy of this message
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 ?> ---- Server IP: 69.147.83.197 Probable Submitter: 141.217.53.148 ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- https://master.php.net/note/edit/105053 Del: integrated -- https://master.php.net/note/delete/105053/integrated Del: useless -- https://master.php.net/note/delete/105053/useless Del: bad code -- https://master.php.net/note/delete/105053/bad+code Del: spam -- https://master.php.net/note/delete/105053/spam Del: non-english -- https://master.php.net/note/delete/105053/non-english Del: in docs -- https://master.php.net/note/delete/105053/in+docs Del: other reasons-- https://master.php.net/note/delete/105053 Reject -- https://master.php.net/note/reject/105053 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#181851) next »