Jump to content

Formatting timestamp as UK date gives today's date only


mkultron

Recommended Posts

Hi guys, I'm putting together a small event system where I want the user to add his own date and time into a textfield (I'll probably make this a series of drop-downs/a date picker later).

This is then stored as a timestamp - "0000-00-00 00:00:00" which displays fine until I try to echo it out as a UK date in this format - jS F Y, which just gives today's date but not the inputted date.

 

 

 

Here's the code I have right now:

 

$result = mysql_query("SELECT * FROM stuff.events ORDER BY eventdate ASC");

echo "<br />";
echo mysql_result($result, $i, 'eventvenue');
echo ", ";

$dt = new DateTime($eventdate);

echo $dt->format("jS F Y"); 

 

 

 

In my mysql table eventdate is set up as follows:

 

field - eventdate

type - timestamp

length/values - blank

default - current_timestamp

collation - blank

attributes - on update CURRENT_TIMESTAMP

null - blank

auto_increment - blank

 

 

Any help as to why this could be happening would be much appreciated, thanks.

Link to comment
Share on other sites

Thanks kickstart, I now have the following set up, but still with only the venue name and today's date:

 

        include('database-connect.php');

	$result = mysql_query("SELECT * FROM stuff.eventstest ORDER BY eventdate ASC");

	$eventdate = mysql_result($result, $i, '$eventdate');

                echo "<br />";
                echo mysql_result($result, $i, 'eventvenue');
			echo ", ";

			$dt = new DateTime($eventdate);
			echo $dt->format("jS F Y");

			echo "<br />";  

Link to comment
Share on other sites

Cool, I've edited as suggested:

 

<?php
        // connect to the database
        include('database-connect.php');

	$result = mysql_query("SELECT * FROM stuff.eventstest ORDER BY eventdate ASC");

	$eventdate = mysql_result($result, $i, '$eventdate');

                echo mysql_result($result, $i, 'eventvenue');
	echo mysql_result($result, $i, 'eventdate');
?>

 

And the value I return is "2012-02-08 10:57:52" (what I wanted, but obviously unformatted).

 

Thanks

MK

Link to comment
Share on other sites

Hi

 

Not sure then as that should work.

 

Although you appear to have an extra $ sign when you try and extract the field from mysql (ie, you want the column  eventdate rather than $eventdate), but I would expect that to stop your echo from working as well.

 

All the best

 

Keith

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.