A
A
Andrey Andreev2015-09-09 14:44:08
PHP
Andrey Andreev, 2015-09-09 14:44:08

Can't make a script that checks the current date on the server and adds +2 days to the number in the tag?

I am learning js. I want to write a simple script that checks the current date on the server and adds +2 days to today's number, and then outputs the result to span.
for example,
today is September 9th, the script looks at today's date, then adds +2 days and outputs the result to span.

<p>До <span id="data">11</span> сентября получите подарок.</p>

how to do it more gracefully

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Valentin, 2019-04-04
@ImVeryStupid

In a loop, we check the following. array element to zero if true then continue counting
foreach | for -> if array_key_exists($key+1, $arr) and $arr[$key+1] ==0

S
Stalker_RED, 2015-09-09
@maaaaaaan

JS in the browser has no idea what time it is on the server. You can use a server script to set the server time on the page.

var serverTimestamp = <?php echo time();?> // или какой там у вас серверный язык
var serverDate = new Date(serverTimestamp)
var day = serverDate.getDay()

It remains to add a deuce and bring it to span
document.getElementById('data').innerHTML = day + 2;

T
Tema, 2015-09-09
@Tem_ka

var today = new Date();
var then = new Date(today.getTime() + 2*60*60*24*1000);
document.getElementById('data').innerText = then.getDate();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question