Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post

    get date of Sunday

    i need a code that will get the "this coming Sunday" date - like if it is Tuesday, it will find the date of the upcoming Sunday, but yet if it is Sunday, display the current date?

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post
    you could do a switch on the current day, say if it's tuesday, you know that there are 5 days until sunday (inc tuesday)... so get the current date and add 5 to the days..... not got chance to code it at the mo - but that principle should work!?

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    632
    Thanks
    1
    Thanked 21 Times in 21 Posts
    How's this:

    Now=new Date();
    Now_Y=Now.getYear();
    Now_M=Now.getMonth();
    Now_D=Now.getDate();
    Now_W=Now.getDay();
    if (Now_Y < 70) { Now_Y=Now_Y*1+2000; }
    if (Now_Y < 1900) { Now_Y=Now_Y*1+1900; }
    if (Now_W != 0) { Now_D=Now_D*1+7-Now_W; }
    Then=new Date(Now_Y,Now_M,Now_D);
    alert(Then);

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Edit: Removed content per.........
    Last edited by Willy Duitt; 06-22-2004 at 02:21 AM.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Posts
    338
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How about this?

    Code:
    Date.prototype.getNextSunday = function() {
    	var nextSunday = this;
    	switch(nextSunday.getDay()) {
    		case 0:	return nextSunday; //it's Sunday!
    		default:	nextSunday.setDate(nextSunday.getDate() + (7 - nextSunday.getDay()));
    				return nextSunday;
    	}
    	return false;
    }
    Hope that helps!

    Happy coding!

  • #6
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    I orginally wrote it for gestation periods but it can be used for weekly chat countdowns and in your case, the mention of sunday makes me think of Church Services.
    -actually... that's exactly what it's for... im setting up a church MultiMedia website at http://media.bangorbaptist.org/

  • #7
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you want to use it to display the time of the next reoccuring scheduled Service or Bible Study the time display I know would need some work. Also, if you would like to use it to display countdowns for several different meetings/events with a little work the script could be adapted to be more object oriented and be reused multiple times.

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    632
    Thanks
    1
    Thanked 21 Times in 21 Posts
    Quote Originally Posted by boeing747fp
    im setting up a church MultiMedia website at http://media.bangorbaptist.org/
    You need to add a PICS label so that Parental-Controls don't block you as a porn site.

  • #9
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    nah.. it's only for members of our media crew

  • #10
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    none of those codes output anything onto the page

  • #11
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by boeing747fp
    none of those codes output anything onto the page
    Hmmm;

    Ok, on behalf of everyone whom tried to help you.....

    Good Luck....

  • #12
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    all i need is a script that shows the date of the upcoming sunday and if it is sunday, show the current date... but i tried the scripts above and nothing is outputted

  • #13
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by boeing747fp
    all i need is a script that shows the date of the upcoming sunday and if it is sunday, show the current date... but i tried the scripts above and nothing is outputted
    Oh;

    You are looking for a script which utterly and completely fits your particular needs without editting or modification upon your part. In that case try posting in the Work Offers/Requests section of this forum and perhaps you can find someone willing to write a script to your specifications.

    Good Luck;
    God Bless....

  • #14
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by boeing747fp
    all i need is a script that shows the date of the upcoming sunday and if it is sunday, show the current date... but i tried the scripts above and nothing is outputted
    Have you tried nolachrymose's suggestion?

    This is how to use his script:

    var today = new Date();
    alert(today.getNextSunday());

    That will alert the date including the time. If you just want to display the date, you need to do it like this:

    var today = new Date();
    var sun = today.getNextSunday();
    alert(sun.getMonth()+1 + "/" + sun.getDate() + "/" + sun.getFullYear())

    Take note that I used alert for demo purposes only.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #15
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    thanks

    Code:
    <script>
    Date.prototype.getNextSunday = function() {
    	var nextSunday = this;
    	switch(nextSunday.getDay()) {
    		case 0:	return nextSunday; //it's Sunday!
    		default:	nextSunday.setDate(nextSunday.getDate() + (7 - nextSunday.getDay()));
    				return nextSunday;
    	}
    	return false;
    }
    var today = new Date();
    var sun = today.getNextSunday();
    document.write(sun.getMonth()+1 + "/" + sun.getDate() + "/" + sun.getFullYear());
    </script>
    that worked.... thanks!


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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