Forums
This topic is locked
DATE FORMAT displays in reverse
Posted 29 Jul 2005 15:14:20
1
has voted
29 Jul 2005 15:14:20 stephen Ludford posted:
I am using mysql database to display information on a dreamweaver php page unfortunalty the date format is idisplay like this 2005-10-09 US i think I need it to display in this format 09-10-2005. the link below show this in actionwww.gigbox.co.uk/the_cluny.php
Cheers
Stephen
Replies
Replied 29 Jul 2005 18:35:13
29 Jul 2005 18:35:13 Jim Castanes replied:
You need to reformat it into a variable and then use echo to display the variable.
Here’s how I did it. <font color=maroon>You'll need to change the first line to get the date from your database. You may not need the “if” statement. That is there incase there is no date in that field. Some reason it would show up with the data 'Wed, Dec 31, 1969' when empty. </font id=maroon>
<font color=maroon>Set the variable</font id=maroon> <font color=orange>$varTheDate</font id=orange>
$timestamp = $row_rsEvents['eDate']; <font color=red><<< This is getting the date from my database</font id=red>
$year = substr($timestamp, 0, 4);
$month = substr($timestamp, 5, 2);
$day = substr($timestamp, 8, 2);
$varTheDate = date('D, M d, Y', mktime(0, 0, 0, $month, $day, $year));
if ($varTheDate == 'Wed, Dec 31, 1969') {
$varTheDate = "No Date Set";
}
<font color=maroon>Then display it with:</font id=maroon>
echo $varTheDate
Here’s how I did it. <font color=maroon>You'll need to change the first line to get the date from your database. You may not need the “if” statement. That is there incase there is no date in that field. Some reason it would show up with the data 'Wed, Dec 31, 1969' when empty. </font id=maroon>
<font color=maroon>Set the variable</font id=maroon> <font color=orange>$varTheDate</font id=orange>
$timestamp = $row_rsEvents['eDate']; <font color=red><<< This is getting the date from my database</font id=red>
$year = substr($timestamp, 0, 4);
$month = substr($timestamp, 5, 2);
$day = substr($timestamp, 8, 2);
$varTheDate = date('D, M d, Y', mktime(0, 0, 0, $month, $day, $year));
if ($varTheDate == 'Wed, Dec 31, 1969') {
$varTheDate = "No Date Set";
}
<font color=maroon>Then display it with:</font id=maroon>
echo $varTheDate