Date question

Date question

am 10.09.2003 11:46:35 von Grant Henderson

How do I convert a postrgesql timestamp
To an english date

E.g.
$order_date =3D "2003-09-10 09:40:30+01";
$date =3D date("d/M/Y", $order_date);
print($date);

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Re: Date question

am 10.09.2003 15:54:46 von Frank Bax

At 05:46 AM 9/10/03, Grant Henderson wrote:

>How do I convert a postrgesql timestamp
>To an english date
>
>E.g.
> $order_date = "2003-09-10 09:40:30+01";
> $date = date("d/M/Y", $order_date);
> print($date);


The input to php "date" function is a unix timestamp, not a string.
Use:
select date_part('epoch',order_date) from ...
instead of
select order_date from ...





>---------------------------(end of broadcast)---------------------------
>TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Re: Date question

am 10.09.2003 15:55:32 von Scott Marlowe

On Wed, 10 Sep 2003, Grant Henderson wrote:

> How do I convert a postrgesql timestamp
> To an english date
>
> E.g.
> $order_date = "2003-09-10 09:40:30+01";
> $date = date("d/M/Y", $order_date);
> print($date);

You can either split out the parts and use mktime to get a timestamp, then
feed that timestamp to date(), or you can do it in postgresql with
something like SET DateStyle TO 'US' and then see how they come out.

Finally, you could use the extract() function to pull the date in the
format you want ahead of time:

select extract(YEAR from field)||'/'||extract(MONTH from
field)||'/'||extract(day from field);

And get it that way.


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Re: Date question

am 10.09.2003 16:32:48 von Robby Russell

Grant Henderson wrote:
> How do I convert a postrgesql timestamp
> To an english date
>
> E.g.
> $order_date = "2003-09-10 09:40:30+01";
> $date = date("d/M/Y", $order_date);
> print($date);
>

Why not just do it in the database before you get to the PHP?


=# SELECT to_char(now(), 'Month-fmdd-yyyy'::text);

to_char
-------------------
September-10-2003
(1 row)


More info:

http://www.postgresql.org/docs/7/interactive/functions2976.h tm

Hope that can help,

-Robby





--
Robby Russell, | Sr. Administrator / Lead Programmer
Command Prompt, Inc. | http://www.commandprompt.com
rrussell@commandprompt.com | Telephone: (503) 222.2783


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster