PHP formating a date

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

Post Reply
dubs
Forum Commoner
Posts: 28
Joined: Tue Oct 12, 2004 4:55 pm

PHP formating a date

Post 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,
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

what is DateofOrder returning?
dubs
Forum Commoner
Posts: 28
Joined: Tue Oct 12, 2004 4:55 pm

Post by dubs »

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 »

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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

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 »

$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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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.
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-
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 »

I solved it, I used the UNIX_TIMESTAMP function in my select statement and all is better.

Cheers

For the help
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

So the q to dubs becomes why is that entry empty?

That's a whole other problem...
Post Reply