Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Java is more sophisticated when it comes to calculating week numbers, whereas SQL-Server DATEPART(WEEK... is more simplistic. I found the following documented <a href="https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html" rel="nofollow noreferrer">here</a></p> <p>"When setting or getting the WEEK_OF_MONTH or WEEK_OF_YEAR fields, Calendar must determine the first week of the month or year as a reference point. The first week of a month or year is defined as the earliest seven day period beginning on getFirstDayOfWeek() and containing at least getMinimalDaysInFirstWeek() "</p> <p><strike>I think this defaults to the <a href="http://en.wikipedia.org/wiki/ISO_week_date" rel="nofollow noreferrer">ISO</a> standards which is the first week of the year with a thursday in (Monday-Sunday weeks where at least 4 days are the year). Consider using:</strike></p> <p>In SQL Server the <code>DATEPART(WEEK, ..)</code> function is much more simplistic, it simply calculates the number of week boundaries (as defined by <code>DATEFIRST</code>) between the first of january, and the input date, so the 1st January will <strong>always</strong> be week 1. You may wish to consider using:</p> <pre><code>SELECT DATEPART(ISO_WEEK, '01/01/2012') </code></pre> <p>This gets the week number as defined by the <a href="http://en.wikipedia.org/wiki/ISO_week_date" rel="nofollow noreferrer">ISO</a> standards, which is the first week of the year with a thursday in (Monday-Sunday weeks where at least 4 days are the year). </p> <p>Since, as stated SQL Server is more simplistic in it's calculations, this can't be configured, which means that you will need to configure your week numbers within Java. Simply ensure you set up your calendar in Java with the correct values for <code>getFirstDayOfWeek()</code> and <code>getMinimalDaysInFirstWeek()</code>:</p> <pre><code>public static Calendar getISOCalendar() { Calendar calendar = Calendar.getInstance(); calendar.setMinimalDaysInFirstWeek(4); calendar.setFirstDayOfWeek(Calendar.MONDAY); return calendar; } </code></pre> <p>Then you can esnsure consistent week numbers.</p> <pre><code>public static void main(String args[]) { Calendar calendar = getISOCalendar(); calendar.set(2012,0,1); System.out.println(calendar.get(Calendar.WEEK_OF_YEAR)); } ------ 52 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload