如何根据日期计算“周数”?(How is the “week number” calculated based on a date?)
对于我正在研究的系统,我需要有一个“两周数”,就像标准周数一样,它只会每14天翻一次而不是7天。
换句话说,我正在寻找算法,而不是代码,来计算一个日期的周数,以及给出年和周数的开始/结束日期。
问题来自于任何一年的第1周通常不是1月1日,甚至可能是在去年12月。 也有几年因此而最终有53周。
例如:
- 2009年第1周开始于2008年 12月12 日
- 因此2009年有一周#53,从2009-12-28到2010-01-03
- 2010年第1周开始于2010-01-04
这些数字是如何得出的?
For a system I'm working on, I need to have a "fortnight number" that works just like the standard week number, it only rolls over every 14 days instead of 7.
In other words, I'm looking for the algorithm, not the code, to calculate a week number from a date, and also the start/end dates given a year and week number.
The question comes from the fact that week 1 in any year is generally not Jan 1st, and it may even be in the previous December. There are also years that end up having 53 weeks because of this.
For example:
- Week 1 2009 started on 2008-12-29
- Thus 2009 had a week #53, from 2009-12-28 to 2010-01-03
- Week 1 2010 started on 2010-01-04
How are these numbers derived?
原文:https://stackoverflow.com/questions/15340394
最满意答案
好吧,当你在左连接的左侧放置一个条件(你的where子句)时,你基本上使左连接无效(对于相关的表)。
即使左侧没有匹配,左连接也可以从右侧返回记录。 但是,当您在左表上放置条件时,您实际上有一个内连接。
我不确定,但我怀疑NHibernate正在检测这一点,并决定你的
OrderBy()
和First()
子句优先于Where()
子句。所以我会把这个问题转过来。 查询并过滤父实体
Valutum
,然后获取子ValutaHistory
并进行排序。var pc = _session.Query<Valutum>() .Where(x => x.ValutaBetegn == updateLine.ProductCurrency) .FetchMany(x => x.ValutaHistory) .OrderByDescending(x => x.ValutaHistoryID) .First();
This works
var pc = _session.Query<ValutaHistory>() .Where(x => x.Valutum.ValutaBetegn == updateLine.ProductCurrency) .OrderByDescending(x => x.ValutaHistoryID) .Fetch(x => x.Valutum) .First();
相关问答
更多-
这个怎么样: RhinoCommons,NHibernate和ASP.NET MVC Part 1 - Setup 还有这个快速的: Linq到NHibernate教程 How about this one: RhinoCommons, NHibernate and ASP.NET MVC Part 1 - Setup And also this quick one: Linq to NHibernate Tutorial
-
Nhibernate和linq问题(Nhibernate and linq problem)[2022-07-26]
如果你.Expand()在你的IQueryable上调用.Expand() ? 所以,假设你有一个会话,它可能看起来像这样: var senders = (from sender in session.Query().Expand("User") where sender.User.Email == fromAddress select sender); 不幸的是,这需要你导入一个NHibernate扩展方法。 Apologies. I was using Q ... -
来自“在DAL中封装数据访问的错误神话” : “我想用NHibernate来设计一个系统/应用程序,但我也希望如此灵活以至于如果我拔掉NHibernate并使用ADO.NET Entity框架或其他框架,那么我的应用程序就不会崩溃。” 总之,我完全反对甚至试图做这样的事情。 它基于有缺陷的假设 这背后的驱动力很大程度上是基于数据访问层使用自己的方言直接访问数据库时构建的历史驱动器,导致需要创建这种封装以支持多个数据库。 这个驱动器的问题在于它不再是一个因素,所有现代的OR / Ms都可以有效地处理多个数据库 ...
-
没有“完整”的LINQ支持。 LINQ除了Objects之外的任何东西都是一个漏洞的抽象。 在对象模型中表达的一些操作很难转换为SQL,反之亦然。 也就是说,NH3中的LINQ提供程序非常实用,并且正在进行大量工作(其中很多内容将在3.0.1版本中显示,将于2011年2月28日左右发布) 好消息是NH你总是有其他选择。 如果你不能用LINQ做一个特定的查询,总会有HQL,Criteria,QueryOver甚至SQL。 它们都与堆栈的其余部分很好地集成。 There is no such thing as ...
-
NHibernate Criteria Query与LINQ to NHibernate(NHibernate Criteria Query vs. LINQ to NHibernate)[2022-06-11]
尽管NHibernate Criteria在性能方面更好,但NHibernate Linq提供了编译时检查。 我很少看到任何项目使用2中的任何一个,因为性能提升微乎其微。 在我的情况下,我通常使用Linq,除非我无法表达它们然后我必须使用ICriteria。 编译时检查的好处超过了较小的性能提升。 Even though NHibernate Criteria is better in terms of performance, NHibernate Linq provides compile time c ... -
这可能工作: Colors.Where(c => Dogs.Any(d => d.Color.Equals(c))) 但是,如果您纯粹根据颜色标识符进行匹配,请尝试以下方法: Colors.Where(c => Dogs.Any(d => d.Color.Id == c.Id)) 这些将为您提供狗使用的所有颜色。 This might work: Colors.Where(c => Dogs.Any(d => d.Color.Equals(c))) However if you are matchin ...
-
为什么不? Linq to hibernate开始深入研究。 Why not? Linq to hibernate starts work deeper then this.
-
在新的提供程序中,您应该使用session。 Query (),Linq是NHibernate.Linq.dll的扩展方法。 使用nh3时应删除此dll。 所以你的例子应该是这样的: session.Query
().ToSortedList(a => a.Date, SortDirection.Ascending); 旁注; 你正在使用WebControls的SortDirection,我的建议是使用componentmodel中的ListSortDirection http://msd ... -
您可以同时使用NHibernate.Search和FluentNHibernate,只需在创建ISessionFactory时连接NHibernate.Search侦听器。 个人意见! 我不喜欢使用linq来使用全文搜索功能,它只是试图隐藏一个愚蠢的api背后的真实且通常强大的界面,并且通常会出现问题或者在此过程中丢失。 (一个例子是linq-to-sql, where user.Alias == "sisve"有一个简单的用户名where user.Alias == "sisve" ,它自动转换为sql ...
-
Dimecasts有几个: http://www.dimecasts.net/Casts/ByTag/NHibernate http://www.dimecasts.net/Casts/ByTag/Linq Dimecasts have a few: http://www.dimecasts.net/Casts/ByTag/NHibernate http://www.dimecasts.net/Casts/ByTag/Linq