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

A coupole of PHP questions

LEGEND ,
Apr 26, 2007 Apr 26, 2007

Copy link to clipboard

Copied


How do you format a date variable?

I've a variable call $DisplayDate which is pulled from the DB in a loop
and is showing 2007-04-26 - I want to get it to display Thu 26 April
2007.

I'm sure it's very easy if you know how . . . . . .

Lastly creating a PHP/MySql recordset in DW8.02 nothing appears in the
recordset panel - is this normal?? I also get a series of javascript
errors before it writes the code to the page. FWIW when you hit the
test button it displays the correct results.

TYVMIA!
--
Buzby
There's nothing more dangerous than a resourceful idiot
TOPICS
Server side applications

Views

263
Translate

Report

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 26, 2007 Apr 26, 2007

Copy link to clipboard

Copied

On 26 Apr 2007 in macromedia.dreamweaver.appdev, Buzby wrote:

> How do you format a date variable?
>
> I've a variable call $DisplayDate which is pulled from the DB in a loop
> and is showing 2007-04-26 - I want to get it to display Thu 26 April
> 2007.

My personal preference is to do it on the MySQL side:

SELECT DATE_FORMAT(myDatefield, '%a %e %M %Y) AS myFormattedDate,
myOtherField FROM myDatabase ...

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

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

Votes

Translate

Report

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 26, 2007 Apr 26, 2007

Copy link to clipboard

Copied

Joe Makowiec wrote:

> On 26 Apr 2007 in macromedia.dreamweaver.appdev, Buzby wrote:
>
> > How do you format a date variable?
> >
> > I've a variable call $DisplayDate which is pulled from the DB in a
> > loop and is showing 2007-04-26 - I want to get it to display Thu 26
> > April 2007.
>
> My personal preference is to do it on the MySQL side:
>
> SELECT DATE_FORMAT(myDatefield, '%a %e %M %Y) AS myFormattedDate,
> myOtherField FROM myDatabase ...
>
> http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html


<fx: sound of small denomination coin hitting the floor>

Thanks - that never occured to me!

--
Buzby
There's nothing more dangerous than a resourceful idiot

Votes

Translate

Report

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 26, 2007 Apr 26, 2007

Copy link to clipboard

Copied

On 26 Apr 2007 in macromedia.dreamweaver.appdev, Buzby wrote:

> Joe Makowiec wrote:
>
>> On 26 Apr 2007 in macromedia.dreamweaver.appdev, Buzby wrote:
>>
>> > How do you format a date variable?
>> >
>> > I've a variable call $DisplayDate which is pulled from the DB in
>> > a loop and is showing 2007-04-26 - I want to get it to display
>> > Thu 26 April 2007.
>>
>> My personal preference is to do it on the MySQL side:
>>
>> SELECT DATE_FORMAT(myDatefield, '%a %e %M %Y) AS myFormattedDate,
>> myOtherField FROM myDatabase ...
>>
>> http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html
>
> <fx: sound of small denomination coin hitting the floor>
>
> Thanks - that never occured to me!

It probably matters little whether you do it in MySQL or PHP. And PHP
is good about converting MySQL dates (YYYYMMDD) into Unix timestamps.
I just have this thing about screwing around with Unix timestamps
unless I need to do date arithmetic. Just For The Record:

<?php
$format = 'D j F Y';
$formattedDate = date($format, strtotime($mysqlDate));
?>

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

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

Votes

Translate

Report

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 27, 2007 Apr 27, 2007

Copy link to clipboard

Copied

LATEST
Joe Makowiec wrote:

> $format = 'D j F Y';
> $formattedDate = date($format, strtotime($mysqlDate));

Thanks - very much appreciated!

--
Buzby
There's nothing more dangerous than a resourceful idiot

Votes

Translate

Report

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