week-number

How to Get the number of weeks in a given year

帅比萌擦擦* 提交于 2019-12-07 14:11:21
问题 Trying to code a correct function that returns the number of weeks in a given year, but without success. Example of the function I'm looking for : int weeks = GetWeeksInYear ( 2012 ) should return 52 weeks // means there are only 52 weeks in 2012. P.s.: in a year can be 52, 53, 54 weeks, not sure about 51 回答1: See the Calendar.GetWeekOfYear method public int GetWeeksInYear(int year) { DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo; DateTime date1 = new DateTime(year, 12, 31);

Ruby On Rails, week number is not the correct one (-1)

浪子不回头ぞ 提交于 2019-12-07 06:18:14
问题 I need the current week number, if I'm not totally mistaken it's week 51 right now? However when testing it in the console I get this. Time.now => 2013-12-19 11:08:25 +0100 Time.now.strftime('%U') => "50" Date.today => Thu, 19 Dec 2013 Date.today.strftime("%U").to_i => 50 Why is that? 回答1: Time.now.strftime('%V') will give you the week number according to ISO 8601. 回答2: why is that? according to %U or %W , The days in the year before the first week are in week 0 (00..53). with %V (as @Graeme

SQLite return wrong week number for 2013?

左心房为你撑大大i 提交于 2019-12-07 00:55:38
问题 I have a simple SQL for calculating week number in my reports on SQLite SELECT STRFTIME('%W', 'date_column') It was correct for 2009-2012. In 2013 I got always the wrong week number. For example SELECT STRFTIME('%W', '2012-02-28') return '09' and this is correct. SELECT STRFTIME('%W', '2013-02-28') return '08' and this is wrong. We have the 9th week. Is there something in SQLite date time functions that I don't understand? Or is it a bug of SQLite? 回答1: CL's answer works fine for OP's

Get week number using date in python

◇◆丶佛笑我妖孽 提交于 2019-12-06 08:17:14
Date is datetime.date(2013, 12, 30) I am trying to get week number using import datetime datetime.date(2013, 12, 30).isocalendar()[1] I am getting output as , 1 Why i am not getting week number of last year , instead i am getting week number of current year? Whats wrong i am doing here ? You are doing nothing wrong, 2013/12/30 falls in week 1 of 2014, according to the ISO8601 week numbering standard : The ISO 8601 definition for week 01 is the week with the year's first Thursday in it. The Thursday in that week is 2014/01/02. Other ways to explain the definition, from the same linked WikiPedia

How to Get the number of weeks in a given year

你。 提交于 2019-12-06 02:08:24
Trying to code a correct function that returns the number of weeks in a given year, but without success. Example of the function I'm looking for : int weeks = GetWeeksInYear ( 2012 ) should return 52 weeks // means there are only 52 weeks in 2012. P.s.: in a year can be 52, 53, 54 weeks, not sure about 51 See the Calendar.GetWeekOfYear method public int GetWeeksInYear(int year) { DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo; DateTime date1 = new DateTime(year, 12, 31); Calendar cal = dfi.Calendar; return cal.GetWeekOfYear(date1, dfi.CalendarWeekRule, dfi.FirstDayOfWeek); } Be

Calendar.getActualMaximum(Calendar.WEEK_OF_YEAR) weirdness

心不动则不痛 提交于 2019-12-05 13:39:57
Either I don't understand the method getActualMaximum(int) or the field WEEK_OF_YEAR, or there's a Sun bug involved (or all three)...could someone explain to me why (at least in a German locale ...) the following code: Locale.setDefault( Locale.GERMAN ); Calendar c = Calendar.getInstance(); c.set( Calendar.YEAR, 2010 ); c.set( Calendar.MONTH, 0 ); c.set( Calendar.DAY_OF_MONTH, 1 ); System.out.println("max: "+c.getActualMaximum( Calendar.WEEK_OF_YEAR )); System.out.println("actual: "+c.get( Calendar.WEEK_OF_YEAR )); produces the following output: max: 52 actual: 53 Here's the Javadoc of

SQLite return wrong week number for 2013?

醉酒当歌 提交于 2019-12-05 05:39:52
I have a simple SQL for calculating week number in my reports on SQLite SELECT STRFTIME('%W', 'date_column') It was correct for 2009-2012. In 2013 I got always the wrong week number. For example SELECT STRFTIME('%W', '2012-02-28') return '09' and this is correct. SELECT STRFTIME('%W', '2013-02-28') return '08' and this is wrong. We have the 9th week. Is there something in SQLite date time functions that I don't understand? Or is it a bug of SQLite? CL's answer works fine for OP's definition of "right", which is not quite the same as ISO definition. ISO week numbers are always in the range 1-53

Joda-Time: Get max number of weeks for particular year

狂风中的少年 提交于 2019-12-04 19:56:20
问题 How do I get the maximum number of weeks for a particular year with Joda-Time? 回答1: new DateTime().withYear(PARTICULAR_YEAR).weekOfWeekyear().getMaximumValue(); @cody Comment Difference between the two methods .withWeekOfWeekyear() and .withWeekyear() Example new DateTime().withDate(2011, 1, 2); 2/1/2011 : Sunday, last day of last week of 2010 (27/12/2010 - 2/1/2011) dayOfWeek : 7 weekOfWeekyear : 52 weekyear : 2010 new DateTime().withDate(2011, 1, 3); 3/1/2011 : Monday, first day of first

Get week of month C# [duplicate]

空扰寡人 提交于 2019-12-04 14:13:35
This question already has an answer here: Calculate week of month in .NET 12 answers I want to find a date are now on week number with c# desktop Application. I've been looking on google, but none that fit my needs. How do I get a week in a month as the example below? Example: I want January 6, 2014 = the first week of January January 30, 2014 = fourth week of January but 1 February 2014 = week 4 in January and 3 February 2014 was the first week in February Here is the method: static int GetWeekNumberOfMonth(DateTime date) { date = date.Date; DateTime firstMonthDay = new DateTime(date.Year,

How to group by week in Entity Framework Core?

巧了我就是萌 提交于 2019-12-04 07:43:27
In Entity Framework 6 I can use SqlFunctions.DatePart() method: var byWeek = data.GroupBy(x => SqlFunctions.DatePart("week", x.Date)); But these classes ( DbFunctions and SqlFunctions are not available in Entity Framework Core) ( reference ). So my question is How can I group by week in Entity Framework core? My current workaround for the missing functionality is var firstMondayOfYear = this.GetFirstMondayOfYear(DateTime.Now.Year); var entries = this.entitiesService.FindForLastMonths(this.CurrentUser.Id, 6) .GroupBy(x => ((int)(x.Date - firstMondayOfYear).TotalDays / 7)) The function