Page 1 of 1
PHP formating a date
Posted: Mon Nov 22, 2004 7:30 am
by dubs
I'm having a bit of trouble formatting a mysql timestamp.
Here's my php code
Code: Select all
<?php
date("d / M / Y",strtotime($orderdetails['DateofOrder']))
?>
But this is what comes out
Richard Walker 01 / Jan / 1970
I'm confused,
Posted: Mon Nov 22, 2004 7:49 am
by John Cartwright
what is DateofOrder returning?
Posted: Mon Nov 22, 2004 8:11 am
by dubs
It returns 01/Jan / 1970, don't understand why
Posted: Mon Nov 22, 2004 8:11 am
by timvw
you can also use the mysql date_format function
Code: Select all
mysql> SELECT DATE_FORMAT('1997-10-04 22:23:00', '%d/%M/%Y');
http://dev.mysql.com/doc/mysql/en/Date_ ... tions.html
if you are going to use, you might want to use UNIX_TIMESTAMP function
Posted: Mon Nov 22, 2004 8:13 am
by John Cartwright
Phenom wrote:what is DateofOrder returning?
i was refering to echo $orderdetails['DateofOrder'];
What does that return
Posted: Mon Nov 22, 2004 8:29 am
by dubs
$getorders = "SELECT * FROM customer RIGHT OUTER JOIN orders ON (customer.Customerid = orders.CustomerID) ORDER BY orders.DateofOrder DESC LIMIT $from, $max_results";
It returns a timestamp field from a mysql database, my query is above
Posted: Mon Nov 22, 2004 10:07 am
by John Cartwright
Phenom wrote:Phenom wrote:what is DateofOrder returning?
i was refering to echo $orderdetails['DateofOrder'];
What does that return
for the 3rd time
Posted: Mon Nov 22, 2004 10:14 am
by Maugrim_The_Reaper
dubs,
$orderdetails['DateofOrder']
What does it contain to start with??? Before you strtotime(), or date() anything. Look it up on the database with phpmyadmin or something... or just echo it from the script.
Posted: Mon Nov 22, 2004 10:52 am
by djot
-
Hi,
for sure DateofOrder returns nada or "" or 0, that's why it shows 1.1.1970
djot
-
Posted: Mon Nov 22, 2004 11:17 am
by dubs
I solved it, I used the UNIX_TIMESTAMP function in my select statement and all is better.
Cheers
For the help
Posted: Mon Nov 22, 2004 11:18 am
by Maugrim_The_Reaper
So the q to dubs becomes why is that entry empty?
That's a whole other problem...