Date question

Поиск
Список
Период
Сортировка
Искать

Date question

От:
"Grant Henderson" <granth@fusion-advertising.co.uk>
Дата:
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);

Re: Date question

От:
Frank Bax <fbax@sympatico.ca>
Дата:
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

Re: Date question

От:
"scott.marlowe" <scott.marlowe@ihs.com>
Дата:
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.

Re: Date question

От:
Robby Russell <rrussell@commandprompt.com>
Дата:
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.htm

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

FAQ