PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
dubs
Forum Commoner
Posts: 28 Joined: Tue Oct 12, 2004 4:55 pm
Post
by dubs » Mon Nov 22, 2004 7:30 am
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,
dubs
Forum Commoner
Posts: 28 Joined: Tue Oct 12, 2004 4:55 pm
Post
by dubs » Mon Nov 22, 2004 8:11 am
It returns 01/Jan / 1970, don't understand why
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Mon Nov 22, 2004 8:11 am
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
Last edited by
timvw on Mon Nov 22, 2004 8:14 am, edited 1 time in total.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Mon Nov 22, 2004 8:13 am
Phenom wrote: what is DateofOrder returning?
i was refering to echo $orderdetails['DateofOrder'];
What does that return
dubs
Forum Commoner
Posts: 28 Joined: Tue Oct 12, 2004 4:55 pm
Post
by dubs » Mon Nov 22, 2004 8:29 am
$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
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Mon Nov 22, 2004 10:07 am
Phenom wrote: Phenom wrote: what is DateofOrder returning?
i was refering to echo $orderdetails['DateofOrder'];
What does that return
for the 3rd time
Maugrim_The_Reaper
DevNet Master
Posts: 2704 Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland
Post
by Maugrim_The_Reaper » Mon Nov 22, 2004 10:14 am
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.
djot
Forum Contributor
Posts: 313 Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:
Post
by djot » Mon Nov 22, 2004 10:52 am
-
Hi,
for sure DateofOrder returns nada or "" or 0, that's why it shows 1.1.1970
djot
-
dubs
Forum Commoner
Posts: 28 Joined: Tue Oct 12, 2004 4:55 pm
Post
by dubs » Mon Nov 22, 2004 11:17 am
I solved it, I used the UNIX_TIMESTAMP function in my select statement and all is better.
Cheers
For the help
Maugrim_The_Reaper
DevNet Master
Posts: 2704 Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland
Post
by Maugrim_The_Reaper » Mon Nov 22, 2004 11:18 am
So the q to dubs becomes why is that entry empty?
That's a whole other problem...