Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format date on page when taken out of MYSQL database 1

Status
Not open for further replies.

jewel464g

Technical User
Jul 18, 2001
198
US
When I pull the data out of my database. The date shows exactly like it is in the database. How can I get it to format in the standard DD/MM/YYYY.

This is what my output looks like.

Start Date End Date Event Name
2002-11-28 2002-11-29 Happy Thanksgiving.


This is my code.

//connect to database and open it
$db = mysql_connect("localhost", "root");
mysql_select_db("cadb",$db);
$tableName = "calendarElem";
$pageName = "elem_calendar.php";
mysql_query(&quot;DELETE from calendarElem where endDate <= curdate()&quot;);
$result = mysql_query(&quot;SELECT * FROM calendarElem ORDER BY startDate&quot;,$db);
echo &quot;<table border=0 cellpadding=5 cellspacing=0><tr><td><b>Start Date</b></td><td><b>End Date</b></td><td><b>Event Name</b></td></tr>&quot;;
if ($myrow = mysql_fetch_array($result)) {
do {
printf(&quot;<tr><td><b>%s</b></td><td><b>%s</b></td><td>%s</td></tr>&quot;, $myrow[&quot;startDate&quot;], $myrow[&quot;endDate&quot;], $myrow[&quot;description&quot;] );
} while ($myrow = mysql_fetch_array($result));
}
echo &quot;</table>&quot;; When faced with a decision, always ask, 'Which would be the most fun?'
 
Try:
printf(&quot;<tr><td><b>%s</b></td><td><b>%s</b></td><td>%s</td></tr>&quot;, date(&quot;d/m/Y&quot;, strtotime($myrow[&quot;startDate&quot;])), date(&quot;d/m/Y&quot;, strtotime($myrow[&quot;endDate&quot;])), $myrow[&quot;description&quot;] );

For more information:

date():
strtotime(): ______________________________________________________________________
TANSTAAFL!
 
whatever happened to SELECTing a date_formatted date from mysql during the query .../boggle

SELECT DATE_FORMAT('2002-11-20', '%D/%m/%Y');
-> 20/11/2002

substitute the date show for the name of your date field and hey presto ...

SELECT some,stuff,other,stuff,DATE_FORMAT(your_date_field, '%D/%m/%Y') from your_database WHERE otherstuff;
______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top