mmarif4u Posted April 21, 2007 Share Posted April 21, 2007 HI, I want to know about time and date. For example i want to send email to customer or want to set the home header with time and date. Now time and date function in ok i know how to do that. But how can i guess or make a function that will show a user that(Good morning,Good Afternoon,Good Evening) depends on time. Any help will appreciated thanks. Quote Link to comment Share on other sites More sharing options...
jitesh Posted April 21, 2007 Share Posted April 21, 2007 server side or client side ? Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted April 21, 2007 Author Share Posted April 21, 2007 Client side. Quote Link to comment Share on other sites More sharing options...
rikker Posted April 21, 2007 Share Posted April 21, 2007 I think your best bet is using Javascipt. Since PHP is server side and the person's browser is client side Javascript would work best...at least that is for displaying it as a header on the page If you want to send out emails to members of your site that are addressed using "Good morning,Good Afternoon,Good Evening", I would think it's best to capture their timezone in Javascript when they register and store that in a database where you are storing their email address. Then each time the email is generated you can customize each email to their specific timezone. now that is my initial thought...keep in mind that while i am working on code for a project I usually go through several revisions of "what the hell was I thinking" before coming up with the correct method. Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted April 21, 2007 Author Share Posted April 21, 2007 Thanks rikker for suggestion, But i dont want to use javascript. Bcoz i did not feel compartable with javascript. I have some idea in php but it always sya Good Morning. I am not sure about it how to configure it. <?php if ((Time("G") >=5) AND (date("G") <= 11 )) echo "Good Morning!"; elseif ((Time("G") >=12) AND (date("G") <=18)) echo "Good Afternoon!"; elseif ((Time("G") >= 19) AND (date("G") <= 4)) echo "Good Evening!"; ?> Quote Link to comment Share on other sites More sharing options...
trq Posted April 21, 2007 Share Posted April 21, 2007 If you want to do this client side, you need Javascript. PHP runs server side only. Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted April 21, 2007 Author Share Posted April 21, 2007 Ok let me do it with server side, then how can i configure the above code to work correctly. Quote Link to comment Share on other sites More sharing options...
trq Posted April 21, 2007 Share Posted April 21, 2007 Server side wont work because PHP's date function always returns the time on the server. So if your server is in the US while your client is in AU, you will be saying good morning where in fact you should be saying good evening. Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted April 21, 2007 Author Share Posted April 21, 2007 Thanks thorpe, this is good idea. How can i do it in javascript, bcoz i am not good in javascript. Quote Link to comment Share on other sites More sharing options...
rikker Posted April 21, 2007 Share Posted April 21, 2007 I am no Javascript wiz either, actually i had to look some of this up to make sure I was not giving you something totolly wrong. Here is what I did and worked for me. Now you may want to change the times I used in this example. I have it set to say Good Afternoon after 6 PM (18) <SCRIPT language="javascript"> var dateNow = new Date(); var clientHour = dateNow.getHours(); if((clientHour >= 1) && (clientHour < 12)){ document.write("Good Morning!") }else if((clientHour >= 12) && (clientHour < 18)){ document.write("Good Afternoon!"); }else if ((clientHour >= 18) && (clientHour <= 24)){ document.write("Good Evening!"); } </SCRIPT> Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted April 23, 2007 Author Share Posted April 23, 2007 Thanks rikker for help.. I will give it a try. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.