View Full Version : Trying To Grasp Time/Date Within TimeFrame
paul41598
05-01-2009, 10:44 PM
I'm working on a mod...and I'm stuck at a probably simple theory.
I have these expiration threads...and some of them are set to expire on certain days. What I essentially want to do is, if today is within 3 days of that expiration date, I want it to change a color.
Now I'm not worried about the color change, but just the theory of how to write this code.
$test = (TIMENOW - (3 * 86400));
$test = vbdate($vbulletin->options['threadexpiration_dateselect'], $test);
//echo $test; echo "<br>";
if ($test <= $thread['thread_expiry']) {
$thread['thread_expiry'] = "nice";
}
I'm stuck there, and I'm probably way off...but if a thread is going to expire within 3 days for example.. I want it to do something. Can anyone somewhat help me out here? The $thread['thread_expiry'] is already a defined variable and has the timestamp of the expiration
Lynne
05-01-2009, 10:56 PM
You need to have thread_expiry as a unix timestamp and then perform your date calculations on it.
paul41598
05-01-2009, 11:14 PM
it is already a unix timestamp in the database ;)
I just have no idea about the calculation part
Lynne
05-01-2009, 11:23 PM
If it already is a unix timestamp, then you can probably grab it out of the database like: SELECT ..... (UNIX_TIMESTAMP(NOW()) - thread.thread_expiry) as test, etc.... and then:
$threedays = 3 * 86400;
if ($thread['test'] < $threedays) {
$thread['thread_expiry'] = "less than three days";
}
Not tested for syntax or to see if it works.
paul41598
05-01-2009, 11:35 PM
Lynne,
Well thats the confusion too is querying the database. Remember my other thread today where in forumdisplay_query hook I had:
$hook_query_fields .= ", thread_expiry";
Well....the problem with extending this query is I don't want to SELECT (UNIX_TIMESTAMP(NOW()) - thread.thread_expiry) , because wont that give me all threads that are expiring in 3 days? I essentially just want to grab all threads and their corresponding expiration date.
THen outside of the query I wanted to write an IF conditional to say "if those threads that have expiry dates and have less than 3 days left before they expire", then turn them red.
is that confusing? Do you need more info? argh
Lynne
05-01-2009, 11:44 PM
I was saying to use that in the query. So something like this:
$hook_query_fields .= ", (UNIX_TIMESTAMP(NOW()) - thread.thread_expiry) as test"; That will return the variable 'test' which is the difference between now and thread_expiry in seconds for that thread. Or it should if I wrote it right... :cool: (I'm not great at queries, so you may want to go look up time stuff on the mysql site to double-check me.)
Then use what I wrote in the other plugin to see if that difference is within three weeks.
paul41598
05-02-2009, 12:25 AM
Ya I get no results...I think the query is off..I'll take a look and post results soon hopefully
I didnt know you could select something like what u put above...? I thought that had to be in the WHERE clause. Guess not huh?
Lynne
05-02-2009, 02:46 AM
You aren't getting any results? Or you aren't getting the value 'test'? If you are suddenly not getting results, then there is something typed wrong in that plugin. You might want to turn off that plugin, see if you get results, then turn it on and see if you get the same threads. Try spitting out the variable in your threadbit and see what number you get.
You might want to try just UNIX_TIMESTAMP() instead of UNIX_TIMESTAMP(NOW()) also. That's something I use on my tracker and I think I had to use NOW() there for one reason or another.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.