Help - Search - Members - Calendar
Full Version: mysql, date
Pixel2Life Forum > Help Section > PHP, ASP, MySQL, JavaScript and other Web/Database Programming Help
derek.sullivan
when you the table row type is DATE, and you use CURDATE() to insert the date, the format is YYYY-MM-DD, is there a way in PHP to rotate the format to MM-DD-YYYY but still inserting it the way it's sapose to in the DB just changing the format on the page it's being displayed from?
derek.sullivan
I figured it out.... For all of you who are wondering as well here is my code:

before: YYYY-MM-DD

CODE
<?php

$date = list($year, $month, $day)=split('[/.-]', $row['date']); // [/.-] searches for the symbol(s) / . or -
$date = "$month-$day-$year";

echo $date;

?>


after: MM-DD-YYYY

enjoy!
rc69
So you know, list() doesn't return anything, so the following line should not have "$date = "
CODE
$date = list($year, $month, $day)=split('[/.-]', $row['date']); // [/.-] searches for the symbol(s) / . or -
derek.sullivan
But it works still doesn't it??? smile.gif
rc69
Only because PHP is interpreted. If it were a compiled language, something would probably yell at you.

Either way, it is not a practice you should get into.
derek.sullivan
witchcraft isn't a practice i should get into either smile.gif
rc69
Ok, congradulations on solving the problem then.
derek.sullivan
battles are hard to win with hard-headed men smile.gif thanks BTW lol
sanitarium
you can use onlt timestamp
i think that's more easy
derek.sullivan
Correct, but I want to get acquainted with all mysql fields, rows, querys, etc etc...
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.