Results 1 to 7 of 7

Thread: JavaScript to display next thursday

  1. #1
    Join Date
    Feb 2008

    JavaScript to display next thursday

    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.

  2. #2
    Join Date
    Dec 2003
    Bucharest, ROMANIA
    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">
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type="text/javascript">
    function whichNext(){
    var whichNext=4;//0=Sunday, 1=Monday ...
    var D=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
    var M=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
    var date=new Date();
    var dif=date.getDay()-whichNext;
    date.setHours(1);//DST pseudobug correction
    var dd=date.getDate();
    var yyyy=date.getFullYear();
    var DD=D[date.getDay()];
    var mm=M[date.getMonth()];
    document.getElementById('myspan').innerHTML=DD+', '+dd+', '+mm+', '+yyyy;
    <span id="myspan"></span>

  3. #3
    Join Date
    Feb 2006
    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.

    function getNextWeekday(UT,M,W){
    	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
    	h= D.getHours();
    	m= D.getMinutes()+'';
    	if(h== 0) h= 12;
    	else if(h>12){
    		p=' pm'
    	return str+' at '+ h+':'+m+p ;
    // test based on EST
    Last edited by mrhoo; 02-28-2008 at 11:58 AM.

  4. #4
    Join Date
    Dec 2003
    Bucharest, ROMANIA
    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.

  5. #5
    Join Date
    Feb 2006

    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.

    function getNextWeekday(S){
    // you could put S here instead of passing it from below
    	H= S.getHours();
    	M= S.getMinutes()+''; 
    	W= S.getDay(); 
    	// 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;
    	else if(H>12){
    		p=' pm'
    	return str+' at '+ H+':'+M+p ;
    // test based on EST
    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-
    Date.daynames= ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
    Date.monthnames= ['January','February','March','April','May','June','July',
    Last edited by mrhoo; 02-28-2008 at 04:04 PM.

  6. #6
    Join Date
    Jan 2014
    The above code works great, but how can you pick every other week. I have tried, but no luck. Thx ahead for any help.

  7. #7
    Join Date
    Mar 2007
    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...

    As for JavaScript, it takes its time from the users operating system which generally for the individuals needs will have a clock set to their local time, this however does not help you in offering a service based on your Thursday Webinar
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... 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...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.13228 seconds
  • Memory Usage 2,915KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (4)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (7)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates