Get week number based on ISO8601 - sql-server

Is there any way in SQL Server to get week number based on specific date which would reflect
according to ISO8601 where Monday is the first day of week?

Just use the aptly named ISO_WEEK Datepart:
iso_week datepart
ISO 8601 includes the ISO week-date system, a numbering system for weeks. Each week is associated with the year in which Thursday occurs. For example, week 1 of 2004 (2004W01) covered Monday, 29 December 2003 to Sunday, 4 January 2004. European countries / regions typically use this style of numbering. Non-European countries / regions typically do not use it.
SELECT DATEPART(ISO_WEEK,YourDate)
FROM dbo.YourTable;

Related

How to call ICU APIs to give ISO date time format instead of default locale based values

Like to get ISO date-time value for option day of week.
https://unicode-org.github.io/icu/userguide/format_parse/datetime/
e local day of week
example: if Monday is 1st day, Tuesday is 2nd ) e or ee
eee
eeee
eeeee
eeeeee 2
Tue
Tuesday
T
Tu
ISO 8601, Monday is the first day of the week. If default locale is en_US, then Sunday become 1st day.
Eg. 2020-10-05, Monday with option 'e' give 2 because my locale is US. I don't see option to force ISO and ignore default locale in https://unicode-org.github.io/icu/userguide/format_parse/datetime/

Trying to calculate the number of days since 1/1/1900 and the DateDiff function is off

I am trying to calculate the number of days that have passed between 1/1/1900 and 5/1/2019.
I have tried this using several dates and get the same out come.
The value returned is 2 days off.
--
-- calculate the number of days between 1/1/1900 and 5/1/2018
--
SELECT DATEDIFF(DAY,CONVERT(DATE,'1/1/1900'),CONVERT(DATE,'5/1/2018'))
Expected Result: 43221
Actual Result: 43219
Thank you for your help!
DATEDIFF returns the number of days between the two dates. So if you want 1900-01-01 to be numbered as day 1, then you must add 1 to any difference you get from DATEDIFF. In Excel, day 0 is 1899-12-31.
Secondly, Excel treats 1900 as a leap year, and has a 29-Feb-1900 (day 60 in the Excel numbering system iirc). This was a holdover from Lotus 1-2-3 which originally used a simplified algorithm for leap years (treating every year divisible by 4 as a leap), and remains for backward compatibility
If you combine these two faults, these account for your off-by-two results.

logic for calculating ISO year from gregorian year and other fields

As mentioned above i need to calculate ISO year from the calendar view,
also i have created a view on top of it for calculating ISO week number but i'm unable figure out the logic for calculating ISO year, can someone please post it as soon as possible.
Thanks in advance.
kishor
structure of calendar view
REPLACE VIEW Sys_Calendar.CALENDAR(
calendar_date,
day_of_week,
day_of_month,
day_of_year,
day_of_calendar,
weekday_of_month,
week_of_month,
week_of_year,
week_of_calendar,
month_of_quarter,
month_of_year,
month_of_calendar,
quarter_of_year,
quarter_of_calendar,
year_of_calendar)
AS
SEL
calendar_date,
DayNumber_Of_Week(calendar_date),
DayNumber_Of_Month(calendar_date),
DayNumber_Of_Year(calendar_date),
DayNumber_Of_Calendar(calendar_date),
DayOccurrence_Of_Month(calendar_date),
WeekNumber_Of_Month(calendar_date),
WeekNumber_Of_Year(calendar_date),
WeekNumber_Of_Calendar(calendar_date),
MonthNumber_Of_Quarter(calendar_date),
MonthNumber_Of_Year(calendar_date),
month_of_calendar,
QuarterNumber_Of_Year(calendar_date),
quarter_of_calendar,
YearNumber_Of_Calendar(calendar_date)
FROM Sys_Calendar.CALENDARTMP;
If you're on a fairly modern version of Teradata, you can use TD_SYSFNLIB.YEARNUMBER_OF_CALENDAR(calendar_date,'ISO')
If we take 2014-12-31 as an example, its ISO week is 1. This function will correspondingly return 2015 as it's ISO year.

Transposed day and month values in MS Access 2007 when using Update Query in SQL View

I have a challenge saving the date to an MS Access 2007 database especially for dates with the day less than the 12th of a month (i.e. the day between 01 to 11) If for example a February date - 07/02/2013 (dd/MM/yyyy) will be saved as 02/07/2013 in the database. While a similar February date 14/02/2013 will also be saved 14/02/2013. Retrieving the two dates: The first date will brought out as 2nd July and the second date will be 14th February.
Notice that the day and month values is transposed for dates less than the 11th. This happens when I use an update query (either from VB 2005 or directly within MS Access using SQL pane). I have set both the system short date settings (in Windows 7 OS) and the Date Format at field level (in the MS Access Table) to dd/MM/yyyy.
try - DateValue("dd-mm-yyyy")
or - Format(Date,"dd-mm-yyyy") as an expression builder.

SSRS BIDS 2008 Parameter Date Range

I have produced a report where the user will need to view financial years data.
So for example April 2010 - March 2011 will have one years data however if the user selects this as in my image, data for January, February, March in 2010 will be brought as well as January, Febrary and March 2011, when I dont want the Jan,Feb,Mar for 2010 as the financial year begins in April.
I therfore need to be able select a data range using parameters to stop bringing data through that I didnt ask for.
Can anyone advise me how to do this?
You can build a month-year key to use instead of your ad-hoc year and month parameters. You can then display it for example as YYYY/MM - so that you can select 2010/04 through 2011/03.
Another option would be to have from month (with year) to month (with year).
Yet another option would be to have a year, month, and number-of-months, selecting 2010, 04, then 12 for number-of-months.
Your two parameters aren't aware of eachother in the way that you want it to be.

Resources