Get the current week starting on Monday with php

1

I have the following question, how to get the current week starting on Monday, I am using the function $week = date('W','02/05/2017'); but it happens that when it is Sunday it shows me the following week, that is if I am in week 5, when it is Sunday I already shows week 6, and I would like to know how to make Sunday continue to be week 5

Could you help me please

    
asked by skycomputer2 30.01.2017 в 23:26
source

2 answers

1

Using the class DateTime :

$fecha = new DateTime("02/05/2017");
$semana = $fecha->format('W');
echo "Semana: $semana";

//=> Semana: 05

Demo

    
answered by 30.01.2017 в 23:49
0

date () is based on the Gregorian calendar that consists of 52 weeks beginning on Monday. With the following code we obtain the current week within the current year:

Current week, from 1 to 52

using date ("W");

    
answered by 31.01.2017 в 01:06