English 中文(简体)
每周按阵列分发信息
原标题:Sorting Information in an array by weeks

I have an array of dates like

array
1 => string  2012-02-27  (length=10)
2 => string  2012-03-02  (length=10)
59 => string  2012-03-05  (length=10)

等等。 这些日期代表人们申请一些事情的日子。 例如,2月27日,3人提出申请,3月1日。

我想做的是,在<代码>2012-02-26至2012-03>的一周建立一个表格。 5人提交了申请。 左栏标题为<代码>Weeks,右侧栏为<编码>收到的申请编号/编码>。

我已经有了按天确定的表格,但周也会有帮助。 我看到了一个员额,谈论了列名周,并尝试利用这一职位,但还是没有工作。

更具体地说,我的问题是,我是如何采取一系列的日期,在几个星期内打破这些日期,并将这些信息列入一个表格?

问题回答

You didn t specify what database engine you were using, but most have a date format field "week of year", so SELECT COUNT, YEAR(date), WEEKOFYEAR(date) FROM stuff GROUP BY YEAR(date), WEEKOFYEAR(date).

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_weekofyear

也许,你想要的是,不要说是非行。

1) convert dates to epoch (seconds) with strtotime()
2) sort array by (numeric now) date with asort()
3) loop through the sorted now array from start date to end date and add the values.

当然,数据库可以更容易地做到这一点。





相关问题
Weird Time Issue in Python

Problem with using times in Python. Terminal > Python >>> calendar.timegm(datetime.datetime.now().utctimetuple()) 1258449380 This time indicates GMT: Tue, 17 Nov 2009 09:16:20 GMT Eclipse ...

How does a .NET process get the culture information?

I have a Windows service running (C#, .NET 2.0) on Windows Server 2003 R2. In one server the System.Threading.Thread.CurrentThread.CurrentCulture is {en-AU} and in the other {en-US}. This has caused a ...

Best way to get maximum Date value in java?

I m writing a bit of logic that requires treating null dates as meaning forever in the future (the date in question is an expiration date, which may or may not exist). Instead of putting in special ...

Date format in SQL Server

Short Question: What s the best date format to use in SQL Server? Long Explanation: We re converting our database from mysql to SQL Server. In mysql we always used int(11) to avoid the daylight ...

Converting asp.net/sql web app to be ime zone savy

Our current app stores all dates via the server s datetime. I m thinking we need to update all datetime values in the database over to UTC time. Now for displaying these dates back to the user, I ...

Check if string is of SortableDateTimePattern format

Is there any way I can easily check if a string conforms to the SortableDateTimePattern ("s"), or do I need to write a regular expression? I ve got a form where users can input a copyright date (as a ...

DateTime in PropertyGrid in .Net

I m currently working on some DateTime properties in a PropertyGrid in c#.Net. Im using the default drop-down datetime picker. My question: Is there any way to show the full date with the time? By ...

热门标签