Date time display

Any problem with PHP can be disscused here
Locked
dexter
Posts: 32
Joined: Fri Mar 09, 2007 1:18 pm

Date time display

Post 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?


leo
Posts: 13
Joined: Tue Mar 13, 2007 4:56 am

Post 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.
anish
Posts: 353
Joined: Fri Apr 27, 2007 12:34 pm
Contact:

Post by anish »

Nice but can we design them in our own style.
Flipper3
Posts: 353
Joined: Tue Feb 28, 2006 12:34 am

Post 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.
Gyanu
Posts: 338
Joined: Mon Jul 30, 2007 2:03 pm
Contact:

Post by Gyanu »

if this coding works then i can keep it in my site?
Image
g007
Posts: 14
Joined: Fri Sep 07, 2007 1:39 am

Post by g007 »

it works. thanx a lot.
Lixas
Posts: 750
Joined: Wed Feb 16, 2005 4:21 pm

Post 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=-
Image
Locked