Page 1 of 1
UNIX_TIMESTAMP
Posted: Thu Jun 16, 2011 6:10 pm
by Temor
Hello, I'm wondering how UNIX_TIMESTAMP works in MySQL. I tried reading about it, but all that expert-mumbo-jumbo made absolutely no sense to me. Can anybody please explain a bit about it?
Also, I'm trying to make a " Users Online " function and I'm wondering what is the best way to insert and extract the date and time from a table?
Re: UNIX_TIMESTAMP
Posted: Thu Jun 16, 2011 7:13 pm
by Tino
One way to see it, essentially, is as the time() function in PHP. It just returns the amount of seconds since 1970-01-01 00:00:00
Re: UNIX_TIMESTAMP
Posted: Thu Jun 16, 2011 7:41 pm
by jacek
Temor wrote:Also, I'm trying to make a " Users Online " function and I'm wondering what is the best way to insert and extract the date and time from a table?
Inserting a timestamp would probably be easiest as you can do the maths with a single number much easier than if you stored a MySQL date format value.
Re: UNIX_TIMESTAMP
Posted: Fri Jun 17, 2011 4:01 pm
by Temor
What is the most reliable way to insert a timestamp?
I really suck at MySQL, so I'm not really sure about anything when it comes to inserting time and dates in a table
Re: UNIX_TIMESTAMP
Posted: Fri Jun 17, 2011 4:14 pm
by jacek
You can use the UNIX_TIMESTAMP() function in the VALUES part of the INSERT query, for example,
INSERT INTO `table` (`list`, `of`, `columns`)
VALUES ('value', UNIX_TIMESTAMP(), 'other value');
would insert a timestamp into the of column in the table table.
Re: UNIX_TIMESTAMP
Posted: Fri Jun 17, 2011 7:40 pm
by Temor
jacek wrote:You can use the UNIX_TIMESTAMP() function in the VALUES part of the INSERT query, for example,
INSERT INTO `table` (`list`, `of`, `columns`)
VALUES ('value', UNIX_TIMESTAMP(), 'other value');
would insert a timestamp into the of column in the table table.
Alright, I'll try it out
Re: UNIX_TIMESTAMP
Posted: Fri Jun 17, 2011 8:50 pm
by Temor
I've hit a snag... I got it to insert it properly. But it keeps repeating itself over and over every time I call the function. ON DUPLICATE KEY ENTRY gives me an error.
Here's my current SQL statement:
$sql = " INSERT INTO `users_online` (`username`,`last_activity`,`null`)
VALUES ('{$username}', UNIX_TIMESTAMP(),'null')";
mysql_query($sql);
Please help me
Re: UNIX_TIMESTAMP
Posted: Sat Jun 18, 2011 12:45 pm
by jacek
Temor wrote:But it keeps repeating itself over and over every time I call the function
What do you mean by that.
Temor wrote:ON DUPLICATE KEY ENTRY gives me an error.
I think you mean ON DUPLICATE KEY UPDATE, also what is the error ?