what i want is this the date variable which i insert and select back in my table to echo should display the correct date like today date is 2005-10-27 when i insert the variable date and select to echo it display this 2012-10-20 also my U_date field i choose date for the type lastly how can i make the date to look like this 10-June-2010 not like this 10-6-2010
<?
$name= ($_POST['name']);
$u_date = date ('h.m.Y');
mysql_query("INSERT INTO user
(name, u_date) VALUES('" . $name . "', '" . $u_date. "')
$query1 = "SELECT * FROM user";
$result1 = mysql_query ($query1) or die('query error开发者_StackOverflow');
$line = mysql_fetch_assoc($result1);
$d_user = $line[name];
$d_date = $line[u_date];
echo"$d_user<br>$d_date";
?>
date ('h.m.Y');
h = 12-hour format of an hour with leading zeros
m = Numeric representation of a month, with leading zeros
Y = A full numeric representation of a year, 4 digits
Are you really wanting to combine hours with months and years?
<?php
echo date('d-F-Y'); // 30-October-2010
echo date('Y-m-d'); // 2010-10-30
?>
See php manual for date formatting
Re obtaining the output you desire:
You could try parsing $line[u_date]
into a time value using the time(...) function, then calling the date(...) function to output the time value in whatever format you desire.
$formatted_date = date('(format string here)', time($line[u_date]));
or you can try different approach through database
SELECT name, DATE_FORMAT(u_date, '%d-%M-%Y') AS u_date from user;
精彩评论