mkultron Posted January 27, 2012 Share Posted January 27, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/255872-formatting-timestamp-as-uk-date-gives-todays-date-only/ Share on other sites More sharing options...
trq Posted January 27, 2012 Share Posted January 27, 2012 "0000-00-00 00:00:00" is not a timestamp. Quote Link to comment https://forums.phpfreaks.com/topic/255872-formatting-timestamp-as-uk-date-gives-todays-date-only/#findComment-1311626 Share on other sites More sharing options...
mkultron Posted January 27, 2012 Author Share Posted January 27, 2012 I changed it to a datetime and it's just giving today's date. Quote Link to comment https://forums.phpfreaks.com/topic/255872-formatting-timestamp-as-uk-date-gives-todays-date-only/#findComment-1311635 Share on other sites More sharing options...
Pikachu2000 Posted January 27, 2012 Share Posted January 27, 2012 If you're storing a fixed event date, chances are you don't want the ON UPDATE CURRENT TIMESTAMP attribute for that field. Quote Link to comment https://forums.phpfreaks.com/topic/255872-formatting-timestamp-as-uk-date-gives-todays-date-only/#findComment-1311716 Share on other sites More sharing options...
mkultron Posted January 30, 2012 Author Share Posted January 30, 2012 It's not anymore, it's just stored as a datetime. This should be such a simple thing but I can't seem to find a solution anywhere. Quote Link to comment https://forums.phpfreaks.com/topic/255872-formatting-timestamp-as-uk-date-gives-todays-date-only/#findComment-1312503 Share on other sites More sharing options...
kickstart Posted January 30, 2012 Share Posted January 30, 2012 Hi Where are you assigning a value to $eventdate? All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/255872-formatting-timestamp-as-uk-date-gives-todays-date-only/#findComment-1312509 Share on other sites More sharing options...
mkultron Posted January 30, 2012 Author Share Posted January 30, 2012 $eventdate should be the eventdate field in from my database table, I've posted all the code I have right now above, do I need to do something like: $eventdate = $row["eventdate"]; Thanks in advance MK Quote Link to comment https://forums.phpfreaks.com/topic/255872-formatting-timestamp-as-uk-date-gives-todays-date-only/#findComment-1312525 Share on other sites More sharing options...
kickstart Posted January 30, 2012 Share Posted January 30, 2012 Hi Yes, if you were bringing back an associative array of the row. Or to continue with how you have done it:- $eventdate = mysql_result($result, $i, '$eventdate'); (assuming $i is set up as the row number you want to retrieve) All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/255872-formatting-timestamp-as-uk-date-gives-todays-date-only/#findComment-1312529 Share on other sites More sharing options...
mkultron Posted January 31, 2012 Author Share Posted January 31, 2012 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 />"; Quote Link to comment https://forums.phpfreaks.com/topic/255872-formatting-timestamp-as-uk-date-gives-todays-date-only/#findComment-1312962 Share on other sites More sharing options...
kickstart Posted January 31, 2012 Share Posted January 31, 2012 Hi Can you echo out $eventdate (unformatted) to check it is a useful value. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/255872-formatting-timestamp-as-uk-date-gives-todays-date-only/#findComment-1312970 Share on other sites More sharing options...
mkultron Posted January 31, 2012 Author Share Posted January 31, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/255872-formatting-timestamp-as-uk-date-gives-todays-date-only/#findComment-1312978 Share on other sites More sharing options...
kickstart Posted January 31, 2012 Share Posted January 31, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/255872-formatting-timestamp-as-uk-date-gives-todays-date-only/#findComment-1313045 Share on other sites More sharing options...
Andy-H Posted January 31, 2012 Share Posted January 31, 2012 Nah, you're right, he echo'ed out the return value of mysql_result($result, $i, 'eventdate'); but his variable was set to mysql_result($result, $i, '$eventdate'); Quote Link to comment https://forums.phpfreaks.com/topic/255872-formatting-timestamp-as-uk-date-gives-todays-date-only/#findComment-1313050 Share on other sites More sharing options...
mkultron Posted February 1, 2012 Author Share Posted February 1, 2012 That works perfectly, thank you so much, kickstart ! Quote Link to comment https://forums.phpfreaks.com/topic/255872-formatting-timestamp-as-uk-date-gives-todays-date-only/#findComment-1313385 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.