Forums
This topic is locked
date format dd/mm/yyyy
Posted 21 Nov 2004 11:58:19
1
has voted
21 Nov 2004 11:58:19 Roger Taylor posted:
Can anyone tell me how to read a mysql date file (yyyy/mm/dd) and display it as dd/mm/yyyy? Im using php. Replies
Replied 08 Dec 2004 16:23:51
08 Dec 2004 16:23:51 Matt Bailey replied:
I believe this extension will do what you are looking for:
www.kaosweaver.com/extensions/details.php?id=68&cid=5
www.kaosweaver.com/extensions/details.php?id=68&cid=5
Replied 13 Dec 2004 10:41:04
13 Dec 2004 10:41:04 Roger Taylor replied:
Thanks. But what I need is the ability to reformat a date from a php mysql database query, not the current date. That extension simply displays the current date in a variety of formats.
Replied 22 Dec 2004 11:57:02
22 Dec 2004 11:57:02 Matt Bailey replied:
I'm reading an excellent book at the moment called 'Dreamweaver MX: Advanced PHP Web Development'. I've just read a bit about displaying dates in different formats (it uses the 'explode' function). The example below doesn't take the date from a database, but it could be tweaked to do so without much effort:
<pre id=code><font face=courier size=2 id=code>
$userDate = "20/09/2002";
$dateArray = explode ("/" ,$userDate);
$americanFormat = $dateArray[1] . "/" . $dateArray[0] . "/" . $dateArray[2];
$mysqlFormat = $dateArray[2] . "-" . $dateArray[1] . "-" . $dateArray[0];
echo "The date in British Format is: " . $userDate . "<br />";
echo "The date in British Format is: " . $americanFormat . "<br />";
echo "The date in British Format is: " . $mysqlFormat . "<br />";
</font id=code></pre id=code>
The opposite can be done to join the various elements of a date back into something that MySQL will recognise. This uses the 'implode' function. An example of it's usage is below. It takes an array (in this case the authors names, but it could be day, month and year taken from a form) and joins it together into a string ready to do whatever you want with it:
<pre id=code><font face=courier size=2 id=code>
$authorArray = array ("Bruno Mairlot", "Gareth Downes-Powell", "Tim Green"
$authors = implode (", ",$authorArray);
echo $authors;
</font id=code></pre id=code>
Let me know if the above is what you're after.
<pre id=code><font face=courier size=2 id=code>
$userDate = "20/09/2002";
$dateArray = explode ("/" ,$userDate);
$americanFormat = $dateArray[1] . "/" . $dateArray[0] . "/" . $dateArray[2];
$mysqlFormat = $dateArray[2] . "-" . $dateArray[1] . "-" . $dateArray[0];
echo "The date in British Format is: " . $userDate . "<br />";
echo "The date in British Format is: " . $americanFormat . "<br />";
echo "The date in British Format is: " . $mysqlFormat . "<br />";
</font id=code></pre id=code>
The opposite can be done to join the various elements of a date back into something that MySQL will recognise. This uses the 'implode' function. An example of it's usage is below. It takes an array (in this case the authors names, but it could be day, month and year taken from a form) and joins it together into a string ready to do whatever you want with it:
<pre id=code><font face=courier size=2 id=code>
$authorArray = array ("Bruno Mairlot", "Gareth Downes-Powell", "Tim Green"
$authors = implode (", ",$authorArray);
echo $authors;
</font id=code></pre id=code>
Let me know if the above is what you're after.
Replied 23 Dec 2004 15:07:25
23 Dec 2004 15:07:25 Matt Bailey replied:
By the way... I think the extension above does reformat the date and not display the current date - at least that's what I use it for unless I'm mistaken.