Date & Time Format

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nitediver
Forum Contributor
Posts: 109
Joined: Tue Feb 24, 2009 9:05 am

Date & Time Format

Post by nitediver »

First,
Does, date with timestamp type in mysql can be format when selected/display?
2010-05-06 19:49:33 >> 19:49:33 05-06-2010 [5-May-2010]

Second,
These code generating date & time like this: 6-5-2010 20:23:45.
I want to make it like this: 06-05-2010 20:23:45.
How to put "0" for number 1 to 9, since it using loop?

Code: Select all

<?
function fdate(){
//Date
echo "<select name=\"day\">";
for($d=1; $d<32; $d++){
echo ("<option>$d</option>");
}
echo "</select>";

//Month
echo "<select name=\"month\">";
for($m=1; $m<13; $m++){
echo ("<option>$m</option>");
}
echo "</select>";

//Year
$d = date(Y);
$b = date(Y)-2;
echo "<select name=\"year\">";
for($d; $d>$b; $d--){
echo ("<option>$d</option>");
}
echo "</select>";
}
?>
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Date & Time Format

Post by AbraCadaver »

mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
nitediver
Forum Contributor
Posts: 109
Joined: Tue Feb 24, 2009 9:05 am

Re: Date & Time Format

Post by nitediver »

Thanks, after doing search I found these.

http://dev.mysql.com/doc/refman/5.1/en/datetime.html

MySQL does not accept timestamp values that include a zero in the day or month column or values that are not a valid date.

What does it mean, is it mean I can't change 6-5-2010 20:23:45 into 06-05-2010 20:23:45 ?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Date & Time Format

Post by AbraCadaver »

nitediver wrote:Thanks, after doing search I found these.

http://dev.mysql.com/doc/refman/5.1/en/datetime.html

MySQL does not accept timestamp values that include a zero in the day or month column or values that are not a valid date.

What does it mean, is it mean I can't change 6-5-2010 20:23:45 into 06-05-2010 20:23:45 ?
No, it means you can't have 00-05-2010 or 06-00-2010.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply