查找当前星期,月份和年份的日期范围 [英] Finding date range for current week, month and year

查看:101
本文介绍了查找当前星期,月份和年份的日期范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有个约会可用日期:

2011-04-05 (i.e., 5th April, 2011)

我想找到当前星期,月份和年份的日期范围

Current Week:  3rd April to 9th April
Current Month: 1st April to 30 April
Current Year:  1st Jan to 31 Dec

我确实知道当前年份始终是1月1日至12月31日,但是当前的月份和周数又如何呢?

如何查找日期,该日期比给定日期早或晚10天. 示例:

假设今天的日期是2011年4月6日 提前10天:2011年3月28日 10天后:2011年4月15日

有人对此有何想法?

解决方案

,您可以使用 strtotime

示例:

    date('d.m.Y',strtotime('last day of this month')) 
date('d.m.Y',strtotime('last monday'))  // for first day of this week

Suppose I have a date available with me:

2011-04-05 (i.e., 5th April, 2011)

I want to find date range for Current Week, Month and Year

Current Week:  3rd April to 9th April
Current Month: 1st April to 30 April
Current Year:  1st Jan to 31 Dec

I do understand that current year would be always 1st Jan to 31Dec, but what about current month and week, How can I find it?

Edit:

How can I find date, which is 10 days earlier or later from a given date. Example:

Suppose today's date is 6th April, 2011 10 day's earlier: 28 March, 2011 10 day's later: 15 April, 2011

Any thoughts on this, guys?

解决方案

you can use strtotime

example :

    date('d.m.Y',strtotime('last day of this month')) 
date('d.m.Y',strtotime('last monday'))  // for first day of this week

这篇关于查找当前星期,月份和年份的日期范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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