Pick up the week correctly

2

Colleagues,

How would I get the week in a given month? For example, if the user next time to access the system (today is 11/18/16), it would appear:

  

Current week: 11/20/2016 to 11/27/2016

I accept suggestions in PHP, Jquery or Javascript.

Thank you

    
asked by anonymous 18.11.2016 / 14:44

3 answers

1

To add this system in PHP is simple.

date('d-m-Y', strtotime("+1 week"));

Using this code you will get the current date and add an extra week in it (% with%).

Accessing today, the output will be

  

25-11-2016

Then to stay as you want, just do

echo date('d-m-Y')." à ". date('d-m-Y', strtotime("+1 week"));
  

18/11/2016 at 11/25/2016

Suggested reading: strtotime ()

An alternative is also to use Javascript.

var date = new Date();
date.setDate(date.getDate() + 7);

Add 7 days more than the current date.

Suggested reading: SetDate ();

    
18.11.2016 / 14:52
1

You can use moment.js :

var primeiroDia = moment().startOf('isoWeek').toDate();
var ultimoDia = moment().endOf('isoWeek').toDate();

console.log(primeiroDia);
console.log(ultimoDia);

jsfiddle :)

    
18.11.2016 / 14:55
0

Made in Pure Js

  var dataHoje = new Date(); //Pegar a data atual
    var diaSemana = dataHoje.getDay(); //Pegar o dia da semana
    var diaSemana = 7 - dataHoje; //Quantidade de dias que faltam para terminar a semana
    var primeiroDia = new Date(dataHoje.setDate(dataHoje.getDate() + dias)); //Primeiro dia da semana que vem
    var ultimoDia = new Date(dataHoje.setDate(primeiroDia.getDate() + 7)); //Segundo dia da semana que vem
    
18.11.2016 / 15:02