0

I need a java-script HTML snippet that will always return the next Sunday at 11:59 pm.

Example: If today's date is "Wednesday, July 18th" the date returned would be "Sunday, July 22nd".

Here I want to update

<p class="price-small">Don't miss this special offer<br />
  Offer ends Tues, Jul 22 at 11:59pm PST</p>
  • i want to update here in my site https://sistershipcircle.com/facilitator-tribe/ , i put lots of effort but still achieved anything, So if you have any solution please tell me. Thankful to you. – Muhammad Danish Jul 18 '18 at 21:51
  • Either show what you tried so we can help you fix it, or hire a real programmer if you don't know how to do it yourself. – Barmar Jul 18 '18 at 21:56
  • I'm not going to look through all the code on your site. – Barmar Jul 18 '18 at 21:56
  • 1
    "I have completed my BSCS in 2017". That statement from your profile is true but you can't solve this simple programming problem? – gforce301 Jul 18 '18 at 21:58
  • 2
    Possible duplicate of [Get next date from weekday in JavaScript](https://stackoverflow.com/questions/1579010/get-next-date-from-weekday-in-javascript) – dmgig Jul 18 '18 at 21:59
  • @gforce301 I'm already written that i'm not good in javascript, I'm doing work in wordpress, laravel, Core PHP. Thanks – Muhammad Danish Jul 18 '18 at 22:02
  • Nice of Santiago to provide you the answer, but googling "javascript add value to date" would have given you the same information. This is why you have skeptical comments here; it doesn't sound like you put in "lots of effort" at all when I spent two minutes looking up an answer. – BobRodes Jul 18 '18 at 22:07

2 Answers2

1

This works correctly:

// get two dates
var today = nextSunday = new Date();
// ajust Sunday
nextSunday.setDate(today.getDate() + (7 - today.getDay()));
nextSunday.setHours(23, 59, 0, 0) ;
// then  format it
var nextSundayFormatted = nextSunday.toLocaleFormat('%a, %b %d %I:%M%p') + ' PST';
// then use it
document.getElementsByClassName("price-small")[0].innerHTML= 
    "Don't miss this special offer<br>Offer ends "+ nextSundayFormatted;
<p class="price-small">Don't miss this special offer<br />
  Offer ends Tues, Jul 22 at 11:59pm PST</p>
Nelson Teixeira
  • 6,297
  • 5
  • 36
  • 73
  • Thanks Netson , but still not working on here, please if you will run here on Run Code Snippet?? Big thanks – Muhammad Danish Jul 18 '18 at 22:40
  • When I run the snippet it shows "Don't miss this special offer/Offer ends Dom, Jul 22 11:59pm PST". Dom is the prefix for Sunday in Brazil (where I live). What is happening to you ? – Nelson Teixeira Jul 18 '18 at 22:42
  • Thanks For your answer , Great Thanks Sir , But its Also your Code and it will Successfully Run , but here you changes little bit var today = new Date(); var nextSunday = new Date(); nextSunday.setDate(today.getDate() + (7 - today.getDay())); document.getElementsByClassName("price-small")[0].innerHTML= "Don't miss this special offer
    Offer ends "+ nextSunday;
    – Muhammad Danish Jul 18 '18 at 22:47
  • 1
    Ok... I changed the answer so it is the exact time and fits to your format string. But happy it worked. maybe you want to try again ? – Nelson Teixeira Jul 18 '18 at 22:49
  • Bundle of thanks Man, It could work successfully. And i have update your new code with previous one. – Muhammad Danish Jul 18 '18 at 22:52
  • @DanishButt I have rejected your edit. In SO the correct form to improve an answer is to write your own answer or comment what you think it deserves improvement then the person who answered edits itself if he/she thinks it's corect. Editions should not alter the code or intention of answers. I have already commented on results based on the use of toLocaleFormat as the formatter. If you change to toDateString the comment would look strange to anyone who reads the anwer after. I recommend that you wait a bit before making editions until you are more familiarized with the SO way of doing things. – Nelson Teixeira Jul 19 '18 at 21:29
  • Please take some time to complete the [tour](http://stackoverflow.com/tour). Also, StackOverflow has an [help center](http://stackoverflow.com/help) with lots of information. Thanks. – Nelson Teixeira Jul 19 '18 at 21:32
  • If you would like to know more about the different forms of formatting a date, this answer may help you: https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date specially the answer from Adrian Maire. – Nelson Teixeira Jul 19 '18 at 21:33
0
            <script>
               var Week = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturnday","Sunday"]; 
           var date = new Date()
           var Distance = 7-(Week.indexOf(date.getDay())+1)        
    date.setDate(date.getDate() + Distance);

    document.getElementByClassName("price-small")[0].innerHtml = "Don't miss this special offer<br>
      Offer ends"+ date;
</script>

this is a beginning, you can customize it

Santiago
  • 76
  • 7