Skip to main content
Inspiring
April 26, 2007
Question

A coupole of PHP questions

  • April 26, 2007
  • 4 replies
  • 298 views

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
This topic has been closed for replies.

4 replies

Inspiring
April 27, 2007
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
Inspiring
April 26, 2007
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
Inspiring
April 26, 2007
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
Inspiring
April 26, 2007
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