Jump to content

Archived

This topic is now archived and is closed to further replies.

dark dude

Forward Timestamps

Recommended Posts

I can't seem to get the following to work...
[quote]if($Category=='Multi'){
$Banlength = UNIX_TIMESTAMP(NOW()) + 864000000;
echo $Banlength;
} else {
echo 'I r t3h h4x';
}[/quote]

It should return 10,000 days into the future if the category is multi, but it doesnt... It doesnt print anything except the usual page markup (So it's not a fault in php).


Anybody got any advice?

Share this post


Link to post
Share on other sites
UNIX_TIMESTAMP and NOW are MySQL functions not PHP function, try:
[code]<?php
$Banlength = time() + 864000000;
echo $Banlength;
?>[/code]

Ken

Share this post


Link to post
Share on other sites
Ok, so far so good, but I want to know how to put that into a database, with its field-type as "timestamp".

At the moment, I input it like this:
[code]$query="UPDATE Users SET Status='Banned', BannedBy='$Username', BannedOn=CURRENT_TIMESTAMP(NOW()), BannedFor='$Banreason', BannedUntil='$Banlength' WHERE Username='$Victim'";
mysql_query($query);[/code]

and when it's put on the databse, it reads on the database that they're banned until 0000-00-00 00:00:00

Any assistance for this bit?

It should read the date off the database as 10,000 days into the future, not the beginning of time...

Share this post


Link to post
Share on other sites
That's because your field is not type timestamp, but type datetime.

BTW, if you had asked the original question in the context of MySQL, like you just did above, you would have gotten a different answer.

Ken

Share this post


Link to post
Share on other sites
[quote author=kenrbnsn link=topic=101430.msg401667#msg401667 date=1153578631]
That's because your field is not type timestamp, but type datetime.

BTW, if you had asked the original question in the context of MySQL, like you just did above, you would have gotten a different answer.

Ken
[/quote]

Oh sorry, my apologies.

Also, it is type timestamp:
http://img95.imageshack.us/img95/2646/timestampcs5.png

Share this post


Link to post
Share on other sites
Remove the default value from that field. Timestamp fields don't have a default value. That default value is for datetime fields. Either you put that default value in by mistake or you changed the field type from datetime to timestamp at some point and left the default value intact.

Ken

Share this post


Link to post
Share on other sites
I tried, but it wont let me change it to anything out of 0000-00-00 00:00:00 format  :(

Share this post


Link to post
Share on other sites
Yes, bumping is allowed, but only once about once a day (not more than twice a day).

What tool are you using to manipulate the database. I us phpmyadmin. Can you post the table definition?

Ken

Share this post


Link to post
Share on other sites
Yea, I use phpmyadmin, the table definition?
I think that's this right?:
BannedUntil timestamp No 0000-00-00 00:00:00
            Browse distinct values Change Drop Primary Unique Index Fulltext

(Sorry for late reply, couldnt get to the internet because the modem died)

Share this post


Link to post
Share on other sites
Dont use TIMESTAMP as the datatype but use INT to store your timestamp, and set the length to 20. For some reason either phpmyadmin/mysql converts the timestamp into date/time form and doesnt keep the timestamp as numbers.

Share this post


Link to post
Share on other sites
It's still only returning the year  ???

In the "BannedUntil" field on the entered row, it now says: 2033...


Edit: Actually, I tried again and it's put 2018015467 into there... o.O

Share this post


Link to post
Share on other sites
Did you change it to int? Also make sure the NULL column is set to 'null 'and not 'not null'. if its 'not null' it put in a defualt value.

Share this post


Link to post
Share on other sites
Yeap, it's set to Int(20) and it's now set to Null

However, it's still outputting the result 2018039464 into the field...

Share this post


Link to post
Share on other sites
That number is the number of second since 1-1-1970 of "today + 10000 days", which is what you wanted in the first place.

To verify in PHP:
[code]<?php
echo date('l, F j, Y G:i',time()+(10000 * 86400)).'<br>';
echo date('l, F j, Y G:i',2018039464);
?>[/code]
You will see that the dates are close, since the number you posted is now 10000 days from a time in the past.

Ken

Share this post


Link to post
Share on other sites
Yeah, that number (2018039464) is a unix timestamp. If you follow kens example above you'll see how to convert that timestamp into a date using PHPs date function, (secound line in kens example above):

[code=php:0]echo date('l, F j, Y G:i',2018039464);[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.