, that fixed the issue but now something wierd is happening. Not many members have logged in since I added the loginDateTime column in my db. So with the first code it just displayed nothing for members that haven't logged and that is fine. But with the new code if they haven't logged in it populates the field anyway with today's date and a time of 00:00:00... Any ideas as to why this is happening?
Please bare with me, I'm a newbie to PHP. But it seems as if your code is only to display [echo] the date. How are you inserting it into the database? Which code are you using for that? And do you also use WHERE statements, to make sure only the column get's updated from the right user? Correct me if I'm wrong ofcourse, I'm just asking things as to what I see above
I see it now. Why aren't you just inserting the right format into the database instead of changing it like this?
Thank you for your time to read my post
Last edited by Sylvester21; 03-13-2007 at 09:59 PM..
Reason: Read it wrong
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Thanked 637 Times in 625 Posts
If you are using a database time, date or datetime data type, then yes you are right, the value is stored in a compressed format that you need not worry about-- you can then use date_format() (if you are using MySQL) to select and format the date however you want it to display.
You are trying to format the date in PHP, but it is much simpler to format it within your query.
Well... that's how you can format dates within PHP... but I was talking about formatting the date as you pull it out of the table using date_format().
$query = "SELECT date_format(date_field, '%m-%d-%Y') from my_table";
But what if you only want to run one query, and then format the date into multiple formats? Ie., grab the date and time, then to break up the date and time into two or more separate variables and formats?
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.