, 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
[edit]
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
Posts: 7,686
Thanks: 42
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().
i.e.
PHP Code:
$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?
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
As I stated in the other post, it's essentially like this
PHP Code:
$query = "SELECT
date_format(date_field, '%m/%d : %l/%i') as format1,
date_format(date_field, '%D day of %M in the year of our lord, %Y at %r') as format2
FROM my_table";
You can put any number of date/time functions in a select query to get any part(s) you want. There is a slew of other date/time fucntions. Take a look a the manual - http://dev.mysql.com/doc/refman/5.0/...functions.html
__________________
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.
As I stated in the other post, it's essentially like this
PHP Code:
$query = "SELECT
date_format(date_field, '%m/%d : %l/%i') as format1,
date_format(date_field, '%D day of %M in the year of our lord, %Y at %r') as format2
FROM my_table";
Isn't this redundant?
Doing it in PHP would then be a lot more efficient.