I want a date format with week number and year in the ISO format of yyyy-'W'ww. However, with only week function available in H2 database, I am able to get only the week number without the year. How can I format in such a way that I add a default year to it. Something like 2016-'W'ww.
Currently, I am using this function (which is definitely not the correct way)
WEEK(PARSEDATETIME(TRUNC(" + this.fieldName + "),'2016ww') WEEK(PARSEDATETIME(TRUNC(" + this.fieldName + "),'2016-ww')
I am not able to get what else can be done. Can anyone help me here
There are several valid solutions in different libraries. However, you need to know that using the standard calendar year "y" would be wrong. Instead you have to use the year-of-weekdate (or called weekbased year) with symbol "Y" (capital letter).
Example using old
Calendar
-stuff:Example using Java-8:
Side note: I have here chosen the locale of France to ensure the correct week configuration needed for ISO-8601.
Example using my library Time4J which is only interesting and gives a surplus value if you also plan to do some arithmetic with obtained calendar week (like
plusWeeks(5)
or plan to get some styled localized output):