Re: [SQL] Datetime in humane format

From: Eric McKeown <ericm(at)palaver(dot)net>
To: Richard Lynch <lynch(at)lscorp(dot)com>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] Datetime in humane format
Date: 1998-09-08 00:32:21
Message-ID: Pine.LNX.3.96.980907192830.16635A-100000@farout.palaver.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sat, 5 Sep 1998, Richard Lynch wrote:

> Date: Sat, 5 Sep 1998 23:27:08 -0500
> From: Richard Lynch <lynch(at)lscorp(dot)com>
> To: pgsql-sql(at)postgreSQL(dot)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(at)lscorp(dot)com
>
>
>
>

_______________________
Eric McKeown
ericm(at)palaver(dot)net
http://www.palaver.net

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message jmjang 1998-09-08 01:45:40 (no subject)
Previous Message Johann Spies 1998-09-07 19:47:43 Database Client (fwd)