Page 1 of 1
Date time display
Posted: Sun Mar 25, 2007 5:47 am
by dexter
Hi all,
I log the date and time people log into my site, I was able to display this using this code
Code: Select all
<?php echo $qry['loginDateTime']; ?>
, but I wanted to change the way the date and time were displayed so I added this
Code: Select all
<?php echo date('d/m/Y H:i:s', strtotime($qry['loginDateTime'])); ?>
, 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?
Posted: Mon Mar 26, 2007 3:10 am
by leo
What's in $qry['lastLoginDate'] when the user hasn't logged in before?
Also, I suggest using unix timestamp or mysql's timestamp to store time / dates. Storing it as string (eg. December 26, 2007) and converting it to another date format is a lot slower than simply storing it in a unix timestamp and converting it using date().
In fact, if you use unix timestamp to store dates in mysql, you can make the default value for the last login column in your table a '0' and use the code:
[PHP]if ($qry['lastLoginDate'] != 0) {
// not the first time to login... showing the date
echo date("d/m/Y", $qry['lastLoginDate']);
} else {
// else, do nothing... or echo "Never"[/PHP]
}
This method is a lot more effecient since you only need to convert it once from timstamp to date, instead of converting it twice from a string, to timestamp, and then back to date.
Posted: Sun May 20, 2007 8:30 am
by anish
Nice but can we design them in our own style.
Posted: Mon May 21, 2007 10:59 pm
by Flipper3
anish wrote:Nice but can we design them in our own style.
Yes, just look here for the codes:
http://us2.php.net/date
Also, your problem is is that when you put that into the database the time will be 00:00:00 because it cannot be read right. Like the database cannot order that when displaying. You need to have it stored normally, but displayed with the edited version.
Posted: Wed Sep 05, 2007 9:29 pm
by Gyanu
if this coding works then i can keep it in my site?
Posted: Wed Sep 12, 2007 3:11 am
by g007
it works. thanx a lot.
Posted: Fri Sep 14, 2007 1:19 pm
by Lixas
Gyanu wrote:if this coding works then i can keep it in my site?
php is free and open source. User also here posted a code that you can use in your own site.
-=LOCKED=-