Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

php format date

Explorer ,
Apr 07, 2008 Apr 07, 2008
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.
TOPICS
Server side applications
564
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 08, 2008 Apr 08, 2008
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.
>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 08, 2008 Apr 08, 2008
LATEST
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/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines