pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Eric McKeown <ericm@palaver.net>
To: Richard Lynch <lynch@lscorp.com>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] Datetime in humane format
Date: Mon, 7 Sep 1998 19:32:21 -0500 (EST)
Message-ID: <Pine.LNX.3.96.980907192830.16635A-100000@farout.palaver.net> (raw)
In-Reply-To: <v02140b15b2177863c44f@[207.152.64.133]>

On Sat, 5 Sep 1998, Richard Lynch wrote:

> Date: Sat, 5 Sep 1998 23:27:08 -0500
> From: Richard Lynch <lynch@lscorp.com>
> To: pgsql-sql@postgreSQL.org
> Subject: [SQL] Datetime in humane format
> 
> So, I followed the advice in the archives and used the datetime type.
> 
> Now, I've got entries like 'Sun Sep 06 00:06:57 1998 EDT' in my table.
> 
> So, how do I turn that into something that a normal human can read?
> 
> "Sep 06 1998 12:06 am" would be nice...

I've written a function to do just that using the datetime type and PHP.
Here it is:

function article_date_format($date) {
        $main = explode(" ", $date);
        $mdy = explode("/", $main[0]);
        $hms = explode(":", $main[1]);
        $sec = explode("\.", $hms[2]);
        $timestamp = mktime($hms[0], $hms[1], $sec[0], $mdy[0], $mdy[1],
$mdy[2]);
        $new_date = date("l, F d, Y", $timestamp);
        $more_date = date("h:i A", $timestamp);
        if (substr($more_date, 0, 1) == "0"):
                $more_date = substr($more_date, 1, strlen($more_date));
        endif;
        $new_date .= "&nbsp   $more_date";
        return $new_date;
}                                                        

--------------

Before I execute that function, I send this command to Postgres (via PHP):

SET DateStyle to 'SQL'

to ensure that my function works properly on the dates I'm fetching.

I'm not sure my solution is the most efficient one, but I know it works
for me.  Hope it helps...

eric

> 
> Or, how do I turn that back into seconds since epoch?  I'm using PHP which
> has a nice date function that I think I can coerce into giving me what I
> want... unless it also thinks that humans understand 00:06:57 as just after
> midnight...
> 
> --
> --
> -- "TANSTAAFL" Rich lynch@lscorp.com
> 
> 
> 
> 

_______________________
Eric McKeown
ericm@palaver.net
http://www.palaver.net




view thread (3+ messages)

Message-ID: <Pine.LNX.3.96.980907192830.16635A-100000@farout.palaver.net>
Permalink:  ../Pine.LNX.3.96.980907192830.16635A-100000@farout.palaver.net/
Also on:    postgresql.org/message-id/Pine.LNX.3.96.980907192830.16635A-100000@farout.palaver.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: ericm@palaver.net, lynch@lscorp.com
  Subject: Re: [SQL] Datetime in humane format
  In-Reply-To: <Pine.LNX.3.96.980907192830.16635A-100000@farout.palaver.net>
  References: <v02140b15b2177863c44f@[207.152.64.133]> <Pine.LNX.3.96.980907192830.16635A-100000@farout.palaver.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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