到目前为止,在php [英] Year and week to date in php

查看:166
本文介绍了到目前为止,在php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从MySQL数据库中提取了两条信息,(2009年,2010年等)和(1-52)。而且我需要将它转换为开始和结束日期的日期。



例如:



<$ p $年龄= 2010年,周= 1将是(2010年1月1日,星期五) - (2010年1月3日,星期日)
年= 2010年,周= 33将是(星期一, 2010年8月16日) - (2010年8月22日,星期日)
年= 2010年,周= 34将(2010年8月23日,星期一) - (2010年8月29日,星期日)

如何在PHP中执行此操作?

解决方案

  $ year =2010; //年份2010 
$ week =01; //第一周

$ date1 = date(l,M jS,Y,strtotime($ year。W。$ week。1)); //一周的第一天
$ date2 = date(l,M jS,Y,strtotime($ year。W。$ week。7)); //最后一天
echo $ date1。 - 。 $ date2;

如果周数低于10,则在数字前添加一个0。 1将不起作用,应为01。


I have two pieces of information extracted from a MySQL database, the year(2009, 2010, ect) and the week (1-52). And I need to convert it in to a date start and date end..

For example:

Year=2010, Week=1 would be (Friday, Jan 1st, 2010) - (Sunday, Jan 3rd, 2010)
Year=2010, Week=33 would be (Monday, Aug 16th, 2010) - (Sunday, Aug 22nd, 2010)
Year=2010, Week=34 would be (Monday, Aug 23rd, 2010) - (Sunday, Aug 29th, 2010)

How would I go about doing that in php ?

解决方案

$year = "2010"; // Year 2010
$week = "01"; // Week 1

$date1 = date( "l, M jS, Y", strtotime($year."W".$week."1") ); // First day of week
$date2 = date( "l, M jS, Y", strtotime($year."W".$week."7") ); // Last day of week
echo $date1 . " - " . $date2;

If week number is under 10 then append a 0 before number. 1 won't work, it should be 01.

这篇关于到目前为止,在php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆