For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > April 2004 > Re: [PHP-DB] Displaying Date from Value in MySQL DB









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PHP-DB] Displaying Date from Value in MySQL DB
John W. Holmes

2004-04-20, 4:32 pm

From: "Justin @ Dreaming in TO" <justin@dreaminginto.com>

> SELECT ditoevents.eventstatus, ditoevents.eventdate,
> DATE_FORMAT(ditoevents.eventdate, '%a, %b %d %Y'), ditoevents.eventtime,
> ditoevents.eventlocation, ditoevents.topic, ditoevents.presenter
> FROM ditoevents
> WHERE ditoevents.eventstatus = 'next'


Use an alias:

SELECT ditoevents.eventstatus, ditoevents.eventdate,
DATE_FORMAT(ditoevents.eventdate, '%a, %b %d %Y') AS myformatteddate,
ditoevents.eventtime,
ditoevents.eventlocation, ditoevents.topic, ditoevents.presenter
FROM ditoevents
WHERE ditoevents.eventstatus = 'next'

Then display $row['myformatteddate'] when you're displaying the data.

---John Holmes...
Tyler Replogle

2004-04-20, 6:31 pm

You could always make your own function. If you need help with that i would
be glad to help there too.



>From: "Justin @ Dreaming in TO" <justin@dreaminginto.com>
>To: php-db@lists.php.net
>Subject: [PHP-DB] Displaying Date from Value in MySQL DB
>Date: Tue, 20 Apr 2004 14:27:30 -0400
>
>Hey All,
>
>Looking to try to figure at small problem.
>
>This is the SQL query I am using to show the next event on a page:
>
>SELECT ditoevents.eventstatus, ditoevents.eventdate,
>DATE_FORMAT(ditoevents.eventdate, '%a, %b %d %Y'), ditoevents.eventtime,
>ditoevents.eventlocation, ditoevents.topic, ditoevents.presenter
>FROM ditoevents
>WHERE ditoevents.eventstatus = 'next'
>
>This is the structure of the table in the MySQL db:
>
>CREATE TABLE ditoevents (
> ID char(3) NOT NULL default '',
> eventID char(2) NOT NULL default '',
> eventstatus varchar(4) NOT NULL default '',
> eventdate date NOT NULL default '0000-00-00',
> eventtime time NOT NULL default '00:00:00',
> eventlocation text NOT NULL,
> topic text NOT NULL,
> presenter text NOT NULL
> ) TYPE=MyISAM;
>
>The problem is, the date value that's being pulled from the DB is being
>displayed as 2004-05-12. I would like the date to be displayed as,
>Wednesday, May 12th, 2004.
>
>How do I do this with PHP. I looked at some of the date functions, and I'm
>a bit .
>
>Thanks,
>
>Justin
>
>--
>PHP Database Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>


________________________________________
_________________________
Stop worrying about overloading your inbox - get MSN Hotmail Extra Storage!
http://join.msn.com/?pgmarket=en-us...2ave/direct/01/
Nicole Swan

2004-04-20, 6:31 pm

In PHP you could do something like:

$mydate =3D date("l, F jS, Y", strtotime($row["eventdate"]));
echo $mydate;

http://us4.php.net/manual/en/function.date.php gives a full listing of =
possible formatting options.

--Nicole
---------------------------
Nicole Swan
Web Programming Specialist
Carroll College CCIT
(406)447-4310


-----Original Message-----
From: Justin @ Dreaming in TO [mailto:justin@dreaminginto.com]
Sent: Tuesday, April 20, 2004 12:28 PM
To: php-db@lists.php.net
Subject: [PHP-DB] Displaying Date from Value in MySQL DB


Hey All,

Looking to try to figure at small problem.

This is the SQL query I am using to show the next event on a page:

SELECT ditoevents.eventstatus, ditoevents.eventdate,=20
DATE_FORMAT(ditoevents.eventdate, '%a, %b %d %Y'), ditoevents.eventtime, =

ditoevents.eventlocation, ditoevents.topic, ditoevents.presenter
FROM ditoevents
WHERE ditoevents.eventstatus =3D 'next'

This is the structure of the table in the MySQL db:

CREATE TABLE ditoevents (
ID char(3) NOT NULL default '',
eventID char(2) NOT NULL default '',
eventstatus varchar(4) NOT NULL default '',
eventdate date NOT NULL default '0000-00-00',
eventtime time NOT NULL default '00:00:00',
eventlocation text NOT NULL,
topic text NOT NULL,
presenter text NOT NULL
) TYPE=3DMyISAM;

The problem is, the date value that's being pulled from the DB is being=20
displayed as 2004-05-12. I would like the date to be displayed as,=20
Wednesday, May 12th, 2004.

How do I do this with PHP. I looked at some of the date functions, and=20
I'm a bit .

Thanks,

Justin

--=20
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Michael Scappa

2004-04-20, 7:33 pm


Add an AS to your statement....

.... ditoevents.eventdate,DATE_FORMAT(ditoevents.eventdate, '%a, %b %d
%Y') AS eventdateformatted, ditoevents.eventtime ...

then $row[eventdateformatted] should contain the date in the way you
want it.

-Mike

-----Original Message-----
From: Tyler Replogle [mailto:dbnm@hotmail.com]
Sent: Tuesday, April 20, 2004 5:36 PM
To: justin@dreaminginto.com; php-db@lists.php.net
Subject: RE: [PHP-DB] Displaying Date from Value in MySQL DB

You could always make your own function. If you need help with that i
would
be glad to help there too.



>From: "Justin @ Dreaming in TO" <justin@dreaminginto.com>
>To: php-db@lists.php.net
>Subject: [PHP-DB] Displaying Date from Value in MySQL DB
>Date: Tue, 20 Apr 2004 14:27:30 -0400
>
>Hey All,
>
>Looking to try to figure at small problem.
>
>This is the SQL query I am using to show the next event on a page:
>
>SELECT ditoevents.eventstatus, ditoevents.eventdate,
>DATE_FORMAT(ditoevents.eventdate, '%a, %b %d %Y'),

ditoevents.eventtime,
>ditoevents.eventlocation, ditoevents.topic, ditoevents.presenter
>FROM ditoevents
>WHERE ditoevents.eventstatus = 'next'
>
>This is the structure of the table in the MySQL db:
>
>CREATE TABLE ditoevents (
> ID char(3) NOT NULL default '',
> eventID char(2) NOT NULL default '',
> eventstatus varchar(4) NOT NULL default '',
> eventdate date NOT NULL default '0000-00-00',
> eventtime time NOT NULL default '00:00:00',
> eventlocation text NOT NULL,
> topic text NOT NULL,
> presenter text NOT NULL
> ) TYPE=MyISAM;
>
>The problem is, the date value that's being pulled from the DB is being


>displayed as 2004-05-12. I would like the date to be displayed as,
>Wednesday, May 12th, 2004.
>
>How do I do this with PHP. I looked at some of the date functions, and

I'm
>a bit .
>
>Thanks,
>
>Justin
>
>--
>PHP Database Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>


________________________________________
_________________________
Stop worrying about overloading your inbox - get MSN Hotmail Extra
Storage!
http://join.msn.com/?pgmarket=en-us.../go/onm00200362
ave/direct/01/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com