- This topic is empty.
-
AuthorPosts
-
June 10, 2010 at 7:57 am #29314
realph
ParticipantHey there guys, I’m trying to show a time greeting on my site. The only problem is that I’d like it to display "Good Afternoon" from 12pm onwards, this doesn’t seem to be working. Site link (http://hollandalekane.co.uk/)
Code used:
Code:Good Evening!“; }
elseif ($hour < 4) { echo "Good Evening!
“; }
elseif ($hour > 3)
{ echo “Good Morning!
“; }
}elseif ($m == “PM”)
{
if ($hour == 12)
{ echo “Good Afternoon!
“; }
elseif ($hour < 7) { echo "Good Afternoon!
“; }
elseif ($hour > 6)
{ echo “Good Evening!
“; }
}
?>June 10, 2010 at 10:36 am #77504MikeC
MemberI’ve just had a look at your site and it says ‘Good afternoon’ for me.
I’m in Spain and it’s 16:35 here, so it seems to be working fine.
June 14, 2010 at 11:01 am #77813realph
ParticipantIs there a way to make my page display this?:
– 12:00 AM – 12:00 PM > (Good Morning)
– 12:00 PM – 06:00PM > (Good Afternoon)
– 06:00 PM – 12:00 AM > (Good Evening)
June 15, 2010 at 6:11 pm #77553eXo
MemberThis works for me:
Code:
<?php
$cD = date(“G”);
if($cD <= ’12’){
echo ‘Good Morning’;
}else if($cD <= ’18’){
echo ‘Good Afternoon’;
}else{
echo ‘Good Evening’;
}
?>But like this it will get the current server time. so if the visiter is from another GMT area then it doesn’t work correctly for that visiter.
June 16, 2010 at 4:23 pm #78081Capt Otis
MemberIf you use php, you will get the server time not the person’s local time (as eXo above me said). You can use javascript to get the person’s local time (or atleast the time they have on their computer) and render the page from there. A quick google search can give you the function for that.
-T
June 18, 2010 at 5:38 pm #78211Pete Oxenham
MemberI agree with the two above posts, it should be generated with Javascript
Javascript:
Code:window.onload = function () {
timegreeting();
}function timegreeting() {
var now = new Date();
var greet;
/* If before 11:00 */
if (now.getHours() < 11) { greet = "Good morning!
“;
}
/* If between 11:00 and 17:00 (5:00, all times are expressed in 24 hr time) */
else if (now.getHours() < 17) { greet = "Whatever
“;
}
/* If after 17:00 */
else {
greet = “Good evening!
“;
}
document.getElementById(“greeting”).innerHTML = greet;
}HTML:
Code:I used that script a long time ago, but it seems to work well
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.