PDA

View Full Version : Morning, afternoon, evening?


qpurser
09-24-2012, 09:50 AM
In my postbit I would like to use the words "morning, afternoon or evening" depending on the time for the day. I am using postbit_legacy in vB4.

For example from 6am to 12PM I want to replace the actual time with "Good Morning", from 12pm until 4pm "Good Afternoon" and for the rest of the day "Good Evening".

What would be the the formula to calculate this and how do I store it in a variable I can use in the postbit_legacy?

Thanks for any help

kh99
09-24-2012, 10:09 AM
You could do this:

$hour = vbdate('G');
if ($hour >= 6 AND $hour < 12)
{
$greeting = "Good Morning";
}
else if ($hour >= 12 AND $hour < 16)
{
$greeting = "Good Afternoon";
}
else
{
$greeting = "Good Evening";
}
vB_Template::preRegister('postbit_legacy', array('greeting' => $greeting));


Then in postbit_legacy, use {vb:raw greeting}

This goes by the user's local time (based on the timezone they selected in their profile). If for some reason you wanted to use the server's time for everybody, you could change vbdate to just date.

I'm kind of curious why you want to put this in postbit_legacy - wouldn't that just repeat the same greeting in every post?

Edit: after posting this I noticed that the similar threads has an existing mod something like this: https://vborg.vbsupport.ru/showthread.php?t=178745

qpurser
09-24-2012, 10:56 AM
Thanks so much for your quick reply. Without people like you many of the newbies would be lost in their attempts to make their forums a little more personal and individual.

You were right it would be silly to put it in the postbit_legacy
I used now your code in my Welcome block and replaced the standard "Welcome back" with the $Greeting variable.
Works like a charm.