The company I work for does a weekly webinar every thursday. What I am trying to find is a script that will display the the following:
"The next free online Webinar is:
Thursday, XX, XXXX at 2 PM"
If someone is logged onto my page on a Wednesday February 27, I need to display to him/her that the next demo will be on Thursday February 28. If the same person logs on on Friday February 29, I need to display to him the next demo date which will be on Thursday March 6. All this displaying the current date as well of course.
Can anyone help? I know this is difficult but any help is appreciated.
It is not difficult. Here's an example:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
var whichNext=4;//0=Sunday, 1=Monday ...
var date=new Date();
date.setHours(1);//DST pseudobug correction
document.getElementById('myspan').innerHTML=DD+', '+dd+', '+mm+', '+yyyy;
You cannot really rely on the user's clock, even for the day of the week,
which is why most time calculations end up on the server.
But usually the clock is ok, and a lot of webpages assume so.
It is not finding next thursday- it is figuring out what 2 pm is to your visitor.
You will need to use the GMT (Universal time) hours for your event's time;
in this example I'm using EST (6 hours behind GMT)
This function has default arguments based on your example,
or you can pass it a new time (GMT hours and minutes) or day of the week.
It returns a string suitable for the text content of an html element.
// test based on EST
UT=UT || 19;// get the GMT hours for this
M= M || 0; // minutes
W= W || 4; // week day index- thursday is 4 (Sunday is 0)
var daynames= ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
var monthnames= ['January','February','March','April','May','June','July',
var str= 'The next meeting is scheduled for ';
var D= new Date(),h,m,p=' am';
var DD= D.getDay();
if(DD== W && D.getUTCHours()< UT) str+= ' Today '; // if it has not started yet
while(D.getDay() < W) D.setDate(D.getDate()+1);
str+= daynames[W]+', '+monthnames[D.getMonth()] +' '+D.getDate();
// convert from UTC to local time
if(h== 0) h= 12;
return str+' at '+ h+':'+m+p ;
Last edited by mrhoo; 02-28-2008 at 11:58 AM.
My code is easily adaptable for the server's clock, on inserting server-side variables into. But I don't think is a good idea. User needs to know when it is his next Thursday. If he has not settled the correct time on his computer, that will be his problem, and there is no way to check/correct that from outside.
Last edited by Kor; 02-28-2008 at 01:51 PM.
I blundered in my solution...
The point is, if an event is going to be online at a specific time,
that time has to be converted from GMT to local time.
2 pm Thursday for me and my event may be 7pm in London, or 11am in California,
or Wednesday in Australia.
If you give the script a starting date that has been calculated as GMT,
the local machine will immediately convert it to local time for all of its calculations.
Otherwise, I'm afraid our mates in England will miss the show-
not to mention Cleveland.
// test based on EST
// you could put S here instead of passing it from below
// the day and time are localized by getting them as local from the GMT Date in S
str= 'The next event is scheduled for ';
var D= new Date(),h,m,p=' am';
if(D.getDay== W && D.getHours()< H) str+= ' Today '; // if it has not started yet
while(D.getDay() != W) D.setDate(D.getDate()+1);
str+= Date.daynames[W]+', '+Date.monthnames[D.getMonth()] +' '+D.getDate();
// get time string
if(H== 0) H= 12;
return str+' at '+ H+':'+M+p ;
var start =new Date(Date.UTC(2008,1,28,19,0,0,0))
// This is the GMT for Thursday, Feb 28 2:00 pm-
// you can set it at date, past or future
// EST is 5 hours behind GMT on that date- it varies
// You will need to set start from your own offset
Oh, almost forgot-
Last edited by mrhoo; 02-28-2008 at 04:04 PM.
The above code works great, but how can you pick every other week. I have tried, but no luck. Thx ahead for any help.
Use PHP for this and the web serve clock, this assumes that the web provider has set the proper time, you find as I have allot of american budget hosts don't bother setting the server time or putting in services to syncronise their server clocks. If this is paid for rackspace and your companies server being hosted in a farm, then your server time will be whatever your company IT department set before shipping or if they bought a rack space, whatever the IT department of the farm set if at all...
Server clocks are just as prone to be wrong, however ... established web time services that give GMT times are accurate and set, so referencing them once a week for example is a good idea and knowing how far ahead / behind GMT you are would allow you to set your server to your local time.
PHP does offer time zone based settings, this again takes its timings from the server...
... and please remember to wrap code with forum BBCode tags:-
[CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]
If you can't think outside the box, you will be trapped forever with no escape...
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)