note 34436 rejected from function.date by nicos

From: Date: Sun, 27 Jul 2003 19:50:57 +0000
Subject: note 34436 rejected from function.date by nicos
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-52803@lists.php.net to get a copy of this message
Note Submitter: danolesen@excite.com ---- When dates screw up !!!! I am sure you've tried getting a date from a search in MySQL, which becomes: "jan. 1 1970 00:00:00", when you try to display it formatted with the date() function. WHY !! - because it becomes a string when you get it from a row. You need to make it a real date before the date() function will give you the string you need. Look at this: $query = "SELECT enq_date FROM enq WHERE id = $id"; $rSetE = mysql_query($query, $lnk); $rowE = mysql_fetch_row($rSetE); $enq_date = $rowE[0]; // the date is now a string using the unformatted $enq_date in a print will yield the right date but in an ugly format: print $enq_date; will output 2003-07-03 23:10:46 using the date() function directly on $enq_date will however not quite work: print date("d-m-Y H:m",$enq_date); will output 01-01-1970 00:00 Now you may have the desired format but a wrong date. The solution is: print date("d-m-Y H:m", strtotime($enq_date)); will output 03-07-2003 10:46

« previous php.notes (#52803) next »