0
php format date
Explorer
,
/t5/dreamweaver-discussions/php-format-date/td-p/403594
Apr 07, 2008
Apr 07, 2008
Copy link to clipboard
Copied
I'm retrieving a date record from my mysql table row.
However, I'd like to reuse this data and show by sometimes showing
just the month and day of the week (apr wed); and at other times
just the month and date (apr 23).
Here's the code I'm using, which obviously isn't working.
<?php echo date($row_rsGigs['date_gig'], 'M D'); ?>
Any help would be appreciated.
Here's the code I'm using, which obviously isn't working.
<?php echo date($row_rsGigs['date_gig'], 'M D'); ?>
Any help would be appreciated.
TOPICS
Server side applications
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/dreamweaver-discussions/php-format-date/m-p/403595#M137717
Apr 08, 2008
Apr 08, 2008
Copy link to clipboard
Copied
Is this what you are trying to do?
<?php echo date('M D', strtotime($row_rsGigs['date_gig'])); ?>
--
Ken Ford
Adobe Community Expert - Dreamweaver
Fordwebs, LLC
http://www.fordwebs.com
"trs.net" <webforumsuser@macromedia.com> wrote in message
news:ftek4p$cg3$1@forums.macromedia.com...
> I'm retrieving a date record from my mysql table row. However, I'd like
> to
> reuse this data and show by sometimes showing just the month and day of
> the
> week (apr wed); and at other times just the month and date (apr 23).
>
> Here's the code I'm using, which obviously isn't working.
> <?php echo date($row_rsGigs['date_gig'], 'M D'); ?>
>
> Any help would be appreciated.
>
<?php echo date('M D', strtotime($row_rsGigs['date_gig'])); ?>
--
Ken Ford
Adobe Community Expert - Dreamweaver
Fordwebs, LLC
http://www.fordwebs.com
"trs.net" <webforumsuser@macromedia.com> wrote in message
news:ftek4p$cg3$1@forums.macromedia.com...
> I'm retrieving a date record from my mysql table row. However, I'd like
> to
> reuse this data and show by sometimes showing just the month and day of
> the
> week (apr wed); and at other times just the month and date (apr 23).
>
> Here's the code I'm using, which obviously isn't working.
> <?php echo date($row_rsGigs['date_gig'], 'M D'); ?>
>
> Any help would be appreciated.
>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
LATEST
/t5/dreamweaver-discussions/php-format-date/m-p/403596#M137719
Apr 08, 2008
Apr 08, 2008
Copy link to clipboard
Copied
trs.net wrote:
> Here's the code I'm using, which obviously isn't working.
> <?php echo date($row_rsGigs['date_gig'], 'M D'); ?>
MySQL dates are stored in human readable format, such as 2008-04-08. The
PHP date() function requires a Unix timestamp. The two don't mix.
Even if they did mix, you have the arguments the wrong way round in the
date() function. The formatting characters come first, not the date.
The best way to deal with your requirement is to get the SQL query to
handle everything for you.
SELECT DATE_FORMAT(date_gig, '%b') AS mon,
DATE_FORMAT(date_gig, '%a') AS weekday,
DAYOFMONTH(date_gig) AS day
FROM myTable
That gives you $row_rsGigs['mon'] as the abbreviated month,
$row_rsGigs['weekday'] as the abbreviated day of the week, and
$row_rsGigs['day'] as the day of the month.
Learn all about MySQL date and time functions here:
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html
--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
> Here's the code I'm using, which obviously isn't working.
> <?php echo date($row_rsGigs['date_gig'], 'M D'); ?>
MySQL dates are stored in human readable format, such as 2008-04-08. The
PHP date() function requires a Unix timestamp. The two don't mix.
Even if they did mix, you have the arguments the wrong way round in the
date() function. The formatting characters come first, not the date.
The best way to deal with your requirement is to get the SQL query to
handle everything for you.
SELECT DATE_FORMAT(date_gig, '%b') AS mon,
DATE_FORMAT(date_gig, '%a') AS weekday,
DAYOFMONTH(date_gig) AS day
FROM myTable
That gives you $row_rsGigs['mon'] as the abbreviated month,
$row_rsGigs['weekday'] as the abbreviated day of the week, and
$row_rsGigs['day'] as the day of the month.
Learn all about MySQL date and time functions here:
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html
--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

