0

I am getting month and its weekno like 1,2,3,4,5 . I want ISO week from it.

Eg. I have April as month and week no 4. I want weekno 16 as output.

Thanks in advance.

user375947
  • 130
  • 12

2 Answers2

1

You can instantiate a new DateTime using the month, increment by the number of weeks, and use the W date format.

<?php
$month = 'April';
$week = 4;

$date = new DateTime("$month 01");
$date->modify("+$week weeks");

echo $date->format('W');

As far as I can tell, the 4th week of April would be ISO week 17, not 16 though.

iainn
  • 16,826
  • 9
  • 33
  • 40
  • Thanks for the solution it worked. but I am still confused. 4th week of april is 16 http://www.onlineconversion.com/day_week_number.htm – user375947 Apr 21 '16 at 20:54
  • When I am setting $month = 'June' and $week = '2' (Date=6june2016). I am getting 24 as output for week no. which is wrong. – user375947 Jun 06 '16 at 05:27
0

date("W"); Will return the week number.

http://php.net/manual/en/function.date.php

Use mktime to set a specific date / time and you'll be sorted!

RefreshCarts
  • 126
  • 1
  • 10