首页 \ 问答 \ 如何根据日期计算“周数”?(How is the “week number” calculated based on a date?)

如何根据日期计算“周数”?(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
更新时间:2023-09-06 21:09

最满意答案

好吧,当你在左连接的左侧放置一个条件(你的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
  • 如果你.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在性能方面更好,但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

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。