FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


how to....





salman_500
hey..

how can a session containing date in "now()" format be displayed in the format of :

date("D M d, Y g:i a");

i tried this :

date("D M d, Y g:i a", $logintime);

but got it showing the wrong date....

now() = 2006-12-01 22:52:06
date("D M d, Y g:i a", $logintime) = Thu Jan 01, 1970 5:00 am

it definetly is wrong...Razz

help please !

thnx in advance ! Very Happy
hexkid
salman_500 wrote:
date in "now()" format

What is this "now()" format?
now() is not a standard PHP function!

The second parameter to the date() function is a timestamp, which is an integer value specifying how many seconds elapsed since 1970, 1st Jan.
PHP will do its best to interpret that parameter well, but sometimes it can't.

date('D M d, Y g:i a', 'hexkid') will be interpreted as date('D M d, Y g:i a', 0);
date('D M d, Y g:i a', '1970, 1st Jan') will be interpreted as date('D M d, Y g:i a', 1970) which is 32 minutes and 50 seconds after midnight!
salman_500
hexkid wrote:
salman_500 wrote:
date in "now()" format

What is this "now()" format?
now() is not a standard PHP function!

The second parameter to the date() function is a timestamp, which is an integer value specifying how many seconds elapsed since 1970, 1st Jan.
PHP will do its best to interpret that parameter well, but sometimes it can't.

date('D M d, Y g:i a', 'hexkid') will be interpreted as date('D M d, Y g:i a', 0);
date('D M d, Y g:i a', '1970, 1st Jan') will be interpreted as date('D M d, Y g:i a', 1970) which is 32 minutes and 50 seconds after midnight!


well when ever i enter data into the database... i use now() to enter the value........

welll if this cant work... do i have to change all values to date() instead?

thnx...
hexkid
salman_500 wrote:
hexkid wrote:
salman_500 wrote:
date in "now()" format
What is this "now()" format?
well when ever i enter data into the database... i use now() to enter the value........


Ah! That's good. That "now()" is a MySQL function. You may want to retrieve the data in UNIX TIME STAMP format.
Code:
SELECT UNIXTIMESTAMP(logintime) FROM accesstable where id=1
and use that as the second parameter to the PHP date function
Code:
echo date('D M d, Y g:i a', $logintime);
salman_500
hexkid wrote:
salman_500 wrote:
hexkid wrote:
salman_500 wrote:
date in "now()" format
What is this "now()" format?
well when ever i enter data into the database... i use now() to enter the value........


Ah! That's good. That "now()" is a MySQL function. You may want to retrieve the data in UNIX TIME STAMP format.
Code:
SELECT UNIXTIMESTAMP(logintime) FROM accesstable where id=1
and use that as the second parameter to the PHP date function
Code:
echo date('D M d, Y g:i a', $logintime);


hey thnx....

this technique didnt work for me.. dunno why...but still i changed all the values to time() instead... that way i can easily use this date command..

thnx !
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.