extracting date information?

Started by Kevin Heflinalmost 28 years ago6 messagesgeneral
Jump to latest
#1Kevin Heflin
kheflin@shreve.net

Any hints or clues on this one?
Using Postgresql6.3 and PHP2

I have a simple database with a list of events, one of the fields is of
the data type "date".

When I call this information from the database, it prints out the date
in the form of "1998-05-05"

What I would really like to do, when this date is retrieved, Is to
format it something like "Thursday May 5, 1998" Anything more
descriptive than "1998-05-05" would be great.

I've tried using the "date(format,date)" call from PHP by saving the
date in a variable, then:
echo date("YMdl","$thedate");

But when it is displayed it always prints out this date:
"1969Dec31Wednesday"

Any suggestions or comments would be appreciated.

Kevin

--
------------------------------------------------------------------
Kevin Heflin | ShreveNet, Inc. | Ph:318.222.2638 x103
VP/Mac Tech | 333 Texas St #619 | FAX:318.221.6612
kheflin@shreve.net | Shreveport, LA 71101 | http://www.shreve.net
------------------------------------------------------------------

#2Sferacarta Software
sferac@bo.nettuno.it
In reply to: Kevin Heflin (#1)
Re: [GENERAL] extracting date information?

On Mon, 18 May 1998, Kevin Heflin wrote:

Any hints or clues on this one?
Using Postgresql6.3 and PHP2

I have a simple database with a list of events, one of the fields is of
the data type "date".

When I call this information from the database, it prints out the date
in the form of "1998-05-05"

What I would really like to do, when this date is retrieved, Is to
format it something like "Thursday May 5, 1998" Anything more
descriptive than "1998-05-05" would be great.

I've tried using the "date(format,date)" call from PHP by saving the
date in a variable, then:
echo date("YMdl","$thedate");

But when it is displayed it always prints out this date:
"1969Dec31Wednesday"

Any suggestions or comments would be appreciated.

If you use "datetime" type instead of "date" and set datestyle = 'Postgres'
your data will be like: Sat Dec 12 00:00:00 1998 CET
instead of: 1998-12-12
Jose'

#3Kevin Heflin
kheflin@shreve.net
In reply to: Sferacarta Software (#2)
Re: [GENERAL] extracting date information?

On Tue, 19 May 1998, Jose' Soares Da Silva wrote:

If you use "datetime" type instead of "date" and set datestyle = 'Postgres'
your data will be like: Sat Dec 12 00:00:00 1998 CET
instead of: 1998-12-12

I actually stumbled across this after my initial post.

Now that my dates are being retreived in this format:
Sat Dec 12 00:00:00 1998 CET

Is there a way to format this to leave off the "time" portion and maybe
the "timezone" info ?

--------------------------------------------------------------------
Kevin Heflin | ShreveNet, Inc. | Ph:318.222.2638 x103
VP/Mac Tech | 333 Texas St #619 | FAX:318.221.6612
kheflin@shreve.net | Shreveport, LA 71101 | http://www.shreve.net
--------------------------------------------------------------------

#4Sferacarta Software
sferac@bo.nettuno.it
In reply to: Kevin Heflin (#3)
Re: [GENERAL] extracting date information?

On Tue, 19 May 1998, Kevin Heflin wrote:

On Tue, 19 May 1998, Jose' Soares Da Silva wrote:

If you use "datetime" type instead of "date" and set datestyle = 'Postgres'
your data will be like: Sat Dec 12 00:00:00 1998 CET
instead of: 1998-12-12

I actually stumbled across this after my initial post.

Now that my dates are being retreived in this format:
Sat Dec 12 00:00:00 1998 CET

Is there a way to format this to leave off the "time" portion and maybe
the "timezone" info ?

try this:

prova=> select c from a;
mydate
----------------------------
Sat Dec 12 00:00:00 1998 CET
(1 row)

prova=> select substring(cast(c as text) from 1 for 10)||substring(cast(c as
text) from 20 for 5) from a;
?column?
---------------
Sat Dec 12 1998
(1 row)

You may also create a function like this:

prova=> create function mydate(datetime) returns text
prova-> as 'select substring(cast($1 as text) from 1 for
10)||substring(cast($1 as text) from 20 for 5) from a;' language 'sql';
CREATE
prova=> select mydate(c) from a;
mydate
---------------
Sat Dec 12 1998
(1 row)
Jose'

#5Jackson, DeJuan
djackson@cpsgroup.com
In reply to: Sferacarta Software (#4)
RE: [GENERAL] extracting date information?

If you use "datetime" type instead of "date" and set datestyle =

'Postgres'

your data will be like: Sat Dec 12 00:00:00 1998 CET
instead of: 1998-12-12

I actually stumbled across this after my initial post.

Now that my dates are being retreived in this format:
Sat Dec 12 00:00:00 1998 CET

Is there a way to format this to leave off the "time" portion and
maybe
the "timezone" info ?

Since you're using php why don't you try (with you date datatype):
$date = '1998-05-05';
list($year, $mon, $day) = explode('-', $date);
echo $date('l M d, Y', mktime(0,0,0,$mon, $day, $year));

#6Noname
wr@tribe.ping.de
In reply to: Jackson, DeJuan (#5)
Re: [GENERAL] extracting date information?

On Tue, May 19, 1998 at 01:27:02PM -0500, Jackson, DeJuan wrote:

Now that my dates are being retreived in this format:
Sat Dec 12 00:00:00 1998 CET

Is there a way to format this to leave off the "time" portion and
maybe
the "timezone" info ?

Since you're using php why don't you try (with you date datatype):
$date = '1998-05-05';
list($year, $mon, $day) = explode('-', $date);
echo $date('l M d, Y', mktime(0,0,0,$mon, $day, $year));

I have a similar problem which could be solved if i knew a possibility to
convert datetime values to date values. There is only a function provided
for the opposite direction.

Werner
--
Werner Reisberger public-key available: voice: +49 234 540294
Schoellmannstr. 20 pgp-public-keys@keys.pgp.net Fax: +49 234 540239
D-44807 Bochum with "get 0xED527449" in the subject