Skip to main content
October 27, 2006
Question

PHP Date Function

  • October 27, 2006
  • 2 replies
  • 338 views
I have been working on a database and my output of a date shows as such.

On my users selection I want to see when they had registered. When I view it shows the following.
2006-10-23 11:30:47, how can I make the format be Oct 23, 2006 11:30:47.

My PHP code shows the following...
<?php echo $row_rsUsers['date']; ?>

In my calendar section I have the following as well where you enter 2006-10-23. I want it to be displayed as October 23, 2006. The PHP code is the same.
<?php echo $row_rsCalendar['date']; ?>

Is there a php function to convert these to a long date?

Thank you,
AdonaiEchad
This topic has been closed for replies.

2 replies

Inspiring
October 27, 2006
On Fri, 27 Oct 2006 17:17:57 +0000 (UTC), "AdonaiEchad"
<webforumsuser@macromedia.com> wrote:

>I have been working on a database and my output of a date shows as such.
>
> On my users selection I want to see when they had registered. When I view it
>shows the following.
> 2006-10-23 11:30:47, how can I make the format be Oct 23, 2006 11:30:47.

In your SQL you need to use DATE_FORMAT

SELECT DATE_FORMAT(tbl_mytable.mydate, '%b %D %Y %T') AS realdate

I called it realdate but you can give it any alias you want.

Here is a useful list fr easy reference:

http://www.dan.co.uk/mysql-date-format/
--
Steve
steve at flyingtigerwebdesign dot com
Inspiring
October 27, 2006
AdonaiEchad wrote:
> $query_rsMonCal = "
> SELECT gencalmon.calID, gencalmon.`date`, gencalmon.title,

Change the above section like this:

$query_rsMonCal = "
SELECT gencalmon.calID, gencalmon.
DATE_FORMAT(`date`, '%b %D %Y %T') AS `date`, gencalmon.title,

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
October 31, 2006
Thank you so much it has worked.
Inspiring
October 27, 2006
On 27 Oct 2006 in macromedia.dreamweaver.appdev, AdonaiEchad wrote:

> I have been working on a database and my output of a date shows as
> such.
>
> On my users selection I want to see when they had registered. When
> I view it shows the following.
> 2006-10-23 11:30:47, how can I make the format be Oct 23, 2006
> 11:30:47.
>
> My PHP code shows the following...
> <?php echo $row_rsUsers['date']; ?>
>
> In my calendar section I have the following as well where you enter
> 2006-10-23. I want it to be displayed as October 23, 2006. The PHP
> code is the same.
> <?php echo $row_rsCalendar['date']; ?>
>
> Is there a php function to convert these to a long date?

It looks like you're using MySQL. You can do it in your SQL statement:

SELECT date_format(myDateField, '%b %e %Y %T') AS myFormattedDate,
username FROM myTable ORDER BY myDateField DESC

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

You can also do this in PHP; however, it involves converting to *nix
timestamps, and my personal preference is for doing it in MySQL.

http://www.php.net/manual/en/function.date.php

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/email.php