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

PHP Date Function

Guest
Oct 27, 2006 Oct 27, 2006
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
TOPICS
Server side applications
338
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 ,
Oct 27, 2006 Oct 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
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 ,
Oct 27, 2006 Oct 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
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
Guest
Oct 27, 2006 Oct 27, 2006
I am not sure but I have tried various versions and still I cannot get it to function. Here is my mysql code.

mysql_select_db($database_conLOMMI, $conLOMMI);
$query_rsMonCal = "
SELECT gencalmon.calID, gencalmon.`date`, gencalmon.title, gencalmon.online
FROM gencalmon
ORDER BY `date` ASC";
$rsMonCal = mysql_query($query_rsMonCal, $conLOMMI) or die(mysql_error());
$row_rsMonCal = mysql_fetch_assoc($rsMonCal);
$totalRows_rsMonCal = mysql_num_rows($rsMonCal)

Thank you,
AdonaiEchad
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 ,
Oct 27, 2006 Oct 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/
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
Guest
Oct 31, 2006 Oct 31, 2006
LATEST
Thank you so much it has worked.
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