Jump to content


Photo

Forward Timestamps


  • Please log in to reply
18 replies to this topic

#1 dark dude

dark dude
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 21 July 2006 - 10:33 PM

I can't seem to get the following to work...

if($Category=='Multi'){
$Banlength = UNIX_TIMESTAMP(NOW()) + 864000000;
echo $Banlength;
} else {
echo 'I r t3h h4x';
}


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?

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 21 July 2006 - 11:54 PM

UNIX_TIMESTAMP and NOW are MySQL functions not PHP function, try:
<?php
$Banlength = time() + 864000000;
echo $Banlength;
?>

Ken

#3 dark dude

dark dude
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 22 July 2006 - 10:31 AM

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:
$query="UPDATE Users SET Status='Banned', BannedBy='$Username', BannedOn=CURRENT_TIMESTAMP(NOW()), BannedFor='$Banreason', BannedUntil='$Banlength' WHERE Username='$Victim'";
mysql_query($query);

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...

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 22 July 2006 - 02:30 PM

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

#5 dark dude

dark dude
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 22 July 2006 - 03:07 PM

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


Oh sorry, my apologies.

Also, it is type timestamp:
http://img95.imagesh...imestampcs5.png

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 22 July 2006 - 03:17 PM

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

#7 dark dude

dark dude
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 22 July 2006 - 08:27 PM

I tried, but it wont let me change it to anything out of 0000-00-00 00:00:00 format  :(

#8 dark dude

dark dude
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 23 July 2006 - 05:13 PM

Offtopic: Also, is bumping topics legal?

#9 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 23 July 2006 - 08:26 PM

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

#10 dark dude

dark dude
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 26 July 2006 - 01:09 PM

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)

#11 dark dude

dark dude
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 26 July 2006 - 05:35 PM

*Bumps - Second paged*

#12 dark dude

dark dude
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 27 July 2006 - 03:34 PM

*bump*

#13 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 27 July 2006 - 03:45 PM

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.

#14 dark dude

dark dude
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 27 July 2006 - 03:50 PM

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

#15 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 27 July 2006 - 03:53 PM

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.

#16 dark dude

dark dude
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 27 July 2006 - 10:32 PM

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...

#17 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 27 July 2006 - 11:35 PM

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:
<?php
echo date('l, F j, Y G:i',time()+(10000 * 86400)).'<br>';
echo date('l, F j, Y G:i',2018039464);
?>
You will see that the dates are close, since the number you posted is now 10000 days from a time in the past.

Ken

#18 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 28 July 2006 - 10:36 AM

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):

echo date('l, F j, Y G:i',2018039464);


#19 dark dude

dark dude
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 28 July 2006 - 11:22 AM

Ohhh, thanks a lot guys, that's solved my problem now ;D :) ;)



~Dark dude~




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users