format 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
johnhelen
Forum Commoner
Posts: 45
Joined: Mon Feb 19, 2007 9:17 pm

format date

Post by johnhelen »

Hello all

I have timestamp field in a table

when I print this value (called $time) as:

echo $time;

I have:

2007-03-13 17:05:07.768449+13

Now I want to display this as:

13-03-07 17:05:07

I tried:

echo date('d-m-y H:i:s', strtotime($time));

It shows

01-01-70 11:59:59

What is wrong here

Please help


Many thanks
Regards
sh
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

That's not a known time format to PHP. "2007-03-13 17:05:07" would be known.
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

In your query that retrieves the data, format the date at that point rather than doing it in PHP.

Look up the date_format function on this page Date Functions
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I believe johnhelen is using Postgre

http://www.postgresql.org/docs/8.2/inte ... etime.html should be of interest.
johnhelen
Forum Commoner
Posts: 45
Joined: Mon Feb 19, 2007 9:17 pm

Post by johnhelen »

Thanks all,
I use function to_date in psql
regards
Post Reply