English 中文(简体)
如何用去年的相同星期数计算特定天数的日期?
原标题:How to calculate the dates of particular days in the same week number from last year?
  • 时间:2012-05-25 09:44:03
  •  标签:
  • php
  • date

我知道很多关于SO的约会问题 但我对这个很不满

我需要做一些报告,为了这样做,我需要确定一些日期。

报告将在星期一进行,我需要在星期前和下星期六确定星期日的日期。

例如,报告将在5月28日星期一进行,我需要的日期是5月20日星期日和5月26日星期六。

然后,我需要同样的价值,但前一周除外,所以5月13日星期日和5月19日星期六。

我认为,这部分会很好,因为它仅仅是一个案例,即把报告的目前日期定在星期一,然后从星期一开始,然后从那里加以操纵。

最后,我无法解决的部分是我提到的第一个星期, 我需要去年的相应日期,

我知道日期函数可以给您周数,但无法根据日期来计算星期日和上星期六的日期。

这就是我所拥有的, 原谅OTT变量名称:

$today     = date( Y/m/d );

// reports run on a Monday and use last Sunday and the following Saturday s date so get yesterday s date first
$yesterday = strtotime ( -1 day , strtotime($today));
$yesterday = date ( Y/m/d , $yesterday);

// start of week (last Sunday)
$start_of_last_week       = strtotime ( -1 week , strtotime($yesterday));
$start_of_last_week       = date ( Y/m/d , $start_of_last_week);

// end of last week (the following Saturday)
$end_of_last_week       = strtotime ( + 6 days , strtotime($start_of_last_week));
$end_of_last_week       = date ( Y/m/d , $end_of_last_week;

// start of previous week
$start_of_previous_week       = strtotime ( -1 week , strtotime($start_of_last_week));
$start_of_previous_week       = date ( Y/m/d , $start_of_previous_week);

// end of previous week
$end_of_previous_week       = strtotime ( + 6 days , strtotime($start_of_previous_week));
$end_of_previous_week       = date ( Y/m/d , previous;



// the start of the same week last year
$start_of_last_week_last_year = strtotime ( -1 year , strtotime($start_of_last_week ));

但上述情况并不正确,因此无法确定下一步应做什么。

非常感谢任何帮助。

最佳回答

您可以找到特定年份的周一日期和周数 。

date(  Y-m-d , strtotime(  2012W21  )); //2011-05-23

"http://php.net/manual/en/datetime.formats.compound.php" rel=“无跟踪” >Comound Date Flaces

问题回答

暂无回答




相关问题
Mysql compaire two dates from datetime?

I was try to measure what is faster and what should be the best way to compare two dates, from datetime record in MySql db. There are several approaches how to grab a date from date time, but I was ...

iPhone Date Picker rolls over to 2010 on December 27th?

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date ...

Convert date Python

I have MMDDYY dates, i.e. today is 111609 How do I convert this to 11/16/2009, in Python?

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

NSDateFormat, super simple! Where am I screwing up?

Ok, this is really simple, maybe I m a getting a bit burnt out, but seems like it should work, Query XML feed, put out date string, format, display in a cell. The issue is I m a getting a NULL ...

sqlite writing a date into an email

I am exporting a date value from sqlite and placing it into an email. The date appears like this 279498721.322872 I am using Objective C in an Iphone App. Does anyone know how to make this export ...

热门标签