[thelist] Date & time formatting

Santilal Parbhu santilal at scorpioneng.co.nz
Sat Apr 15 05:27:41 CDT 2006


I have tries this but I can't make it accept the input format dd/m/y.  This
is the code I am using to store the date.

$year = '/06';
		$entered_date = "{$HTTP_POST_VARS['matchdate']}";
		$ddate = $entered_date . $year;

		$ddate = strtotime("$ddate");
		$query = "UPDATE alexbbdraw SET
match_time='{$HTTP_POST_VARS['match_time']}', matchdate=('$ddate'),
					WHERE round_id = '{$HTTP_POST_VARS['round']}' AND game_no =
'{$HTTP_POST_VARS['game_no']}' AND grade='$grd'";

You can see that actually I am inputing the format dd/mm.  The year is
concatenated onto the end of the date.  I am posting the date to mysql via a

When I read the date back, I am using the following code.

while ($row = mysql_fetch_row ($r))
				$row[3]= date( 'j M', $row[3]);
				$row[4]= date( 'g:ia', time($row[3]));
				//Start a row of data.
				echo "\n<tr>";
				//Print out each row.
				foreach ($row as $data)

				echo "\n\t<td>$data</td>";
				//Finish row
				echo "\n</tr>";

I am reading the data back row by row to print out as a table.  $row[3]is
the unix time stamped date.  When I entered 10/5 as the date (May 10), the
printout said 5 Oct.  Any ideas??



-----Original Message-----
From: thelist-bounces at lists.evolt.org
[mailto:thelist-bounces at lists.evolt.org]On Behalf Of Max Schwanekamp
Sent: Friday, 14 April 2006 8:30 p.m.
To: thelist at lists.evolt.org
Subject: Re: [thelist] Date & time formatting

> From: Santilal Parbhu
> I am sure that this problem has been encountered by many.  I
> am using a PHP
> 4.0.4 to query a mysql database.  I want to be able to enter
> times and dates in a format like say "12:00pm May 21", and I
> want to be able to display it on my website in the same
> format.  The yyyy-m-dd format is not very user friendly.

PHP's strtotime() may help you allow some more flexible date input formats.
For the dates in MySQL, I'd suggest you store them as unix timestamps, and
format them according to your (or your users' preferences).  So this way you
can format the user-entered date as a unix timestamp, store it that way, and
pull it back out as such, and use date() in PHP to format it.  (Or use
DATE_FORMAT() in your SELECT query). HTH.

Max Schwanekamp


* * Please support the community that supports you.  * *

For unsubscribe and other options, including the Tip Harvester
and archives of thelist go to: http://lists.evolt.org
Workers of the Web, evolt !

More information about the thelist mailing list