Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get date from week number & day number and year?

I'm trying to get the date from the week number, day number and year.

For eg:

week number = 52   
day number = 4 (of week 52)  
year = 2013  

In this case, the date should be 26-12-2013.

How can I do it using PHP? I've already tried with strtotime(), but I'm confused about the formats. Can someone help?

like image 801
Code Avatar asked Dec 26 '13 07:12

Code


People also ask

How do I get weekly dates in Excel?

The WEEKNUM Function[1] is an Excel DATE and TIME Function. It will return the week number of a specific date. The function will return an integer that represents a week number from 1 to 52 weeks of the year.

How do you convert a week number to a date in sheets?

How to get the date from a week number. To get the date of the Monday in a week, use =DATE( A1 , 1, -3 + 7 * B1 - WEEKDAY(DATE( A1 , 1, 4), 2) + 1) . Cell A1 contains the four-digit year (e.g. 2022), and cell B2 contains the week number (1-53).

How do I convert a week number to a month in Excel?

If you just need to get the month as Arabic number, you can use this formula =MONTH(DATE(A2,1,B2*7-2)-WEEKDAY(DATE(B2,1,3))). Tip: In the above formulas, A2 indicates the year cell, B2 is the week number cell.


1 Answers

Make use of setISODate()

<?php
$gendate = new DateTime();
$gendate->setISODate(2013,52,4); //year , week num , day
echo $gendate->format('d-m-Y'); //"prints"  26-12-2013
like image 85
Shankar Narayana Damodaran Avatar answered Oct 19 '22 03:10

Shankar Narayana Damodaran