pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Date question
4+ messages / 4 participants
[nested] [flat]

* Date question
@ 2003-09-10 09:46  Grant Henderson <granth@fusion-advertising.co.uk>
  0 siblings, 2 replies; 4+ messages in thread

From: Grant Henderson @ 2003-09-10 09:46 UTC (permalink / raw)
  To: pgsql-php

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);



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Date question
@ 2003-09-10 13:54  Frank Bax <fbax@sympatico.ca>
  0 siblings, 0 replies; 4+ messages in thread

From: Frank Bax @ 2003-09-10 13:54 UTC (permalink / raw)
  To: pgsql-php; +Cc: Grant Henderson <granth@fusion-advertising.co.uk>

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




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Date question
@ 2003-09-10 13:55  scott.marlowe <scott.marlowe@ihs.com>
  parent: Grant Henderson <granth@fusion-advertising.co.uk>
  1 sibling, 0 replies; 4+ messages in thread

From: scott.marlowe @ 2003-09-10 13:55 UTC (permalink / raw)
  To: Grant Henderson <granth@fusion-advertising.co.uk>; +Cc: pgsql-php

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.




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Date question
@ 2003-09-10 14:32  Robby Russell <rrussell@commandprompt.com>
  parent: Grant Henderson <granth@fusion-advertising.co.uk>
  1 sibling, 0 replies; 4+ messages in thread

From: Robby Russell @ 2003-09-10 14:32 UTC (permalink / raw)
  To: Grant Henderson <granth@fusion-advertising.co.uk>; +Cc: pgsql-php

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




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2003-09-10 14:32 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-09-10 09:46 Date question Grant Henderson <granth@fusion-advertising.co.uk>
2003-09-10 13:55 ` scott.marlowe <scott.marlowe@ihs.com>
2003-09-10 14:32 ` Robby Russell <rrussell@commandprompt.com>
2003-09-10 13:54 Re: Date question Frank Bax <fbax@sympatico.ca>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox