Current week is ...
Week 26
Week 26 is from Monday, June 27th, 2022 until (and including) Sunday, December 26, 2021.
Week number according to the ISO-8601 standard, weeks starting on Monday. The first week of the year is the week that contains that year's first Thursday (='First 4-day week'). ISO representation: 2021-W51
The highest week number in a year is either 52 or 53.
2021 has 52 weeks.
ISO 8601 is not the only week numbering system in the world, other systems use weeks starting on Sunday (US) or Saturday (Islamic).
Programming routines
Microsoft Excel / LibreOffice Calc
1 2 3
=ISOWEEKNUM(TODAY()) // or (in older versions): =WEEKNUM(TODAY(),21)
Where the return type '21' is ISO-8601 (week starting on Monday).
In Excel 2007 your best choice is WEEKNUM(TODAY(),2) (2=week starting Monday).
WEEKNUM(TODAY()) will show the week number with weeks starting on Sunday (return type = 1).
Google Docs Spreadsheet
1
=WEEKNUM(TODAY();21)
Type (here '21') is compatible with Excel/LibreOffice, 21 is ISO-8601
PHP
1
$weekNumber = date("W");
or date("W", epoch) for other week numbers. Remember to use capital 'W' not 'w'.
Python
1
datetime.date.today().isocalendar()[1]
PERL
1
my $weekNumber = POSIX::strftime("%V", gmtime time);
Replace time with other epoch/UNIX timestamps for other week numbers.
Java
1 2
Calendar now = Calendar.getInstance(); now.get(Calendar.WEEK_OF_YEAR);
Use WEEK_OF_YEAR in the Calendar class.
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Date.prototype.getWeek = function () { var target = new Date(this.valueOf()); var dayNr = (this.getDay() + 6) % 7; target.setDate(target.getDate() - dayNr + 3); var firstThursday = target.valueOf(); target.setMonth(0, 1); if (target.getDay() != 4) { target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7); } return 1 + Math.ceil((firstThursday - target) / 604800000); } var d= new Date(); alert(d.getWeek());
Extend the Date class using the above code.
MySQL
1
SELECT WEEKOFYEAR(NOW())
Replace now() with other dates eg. SELECT WEEKOFYEAR('2021-02-20');
(You can also use the WEEK function with mode=3 select week(now(),3))
PostgreSQL
1
SELECT * FROM EXTRACT(WEEK from current_date())
MS SQL
1
SELECT DATEPART( wk, GETDATE() )
Oracle
1
SELECT to_char(sysdate, 'IW') FROM DUAL
IW: Week of year (1-52 or 1-53) based on the ISO-8601 standard.
WW: Week of year (1-53) where week 1 starts on the first day of the year and continues to the seventh day of the year (Mostly NOT used)
iSeries SQL
1
SELECT WEEK(NOW()) from sysibm.sysdummy1
iPhone/Mac
1 2
[NSString stringWithFormat:@"Week %d", [calendar ordinalityOfUnit:NSWeekCalendarUnit inUnit:NSYearCalendarUnit forDate:date]];
iPhone/iOS/Swift
1 2 3 4 5 6 7
let gregorian = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)! gregorian.firstWeekday = 2 // Monday gregorian.minimumDaysInFirstWeek = 4 let components = gregorian.components(.WeekOfYearCalendarUnit | .YearForWeekOfYearCalendarUnit, fromDate: date) let week = components.weekOfYear let year = components.yearForWeekOfYear
R
1
lubridate::week()
Ruby
1
week_number = Time.now.strftime("%U")
Replace Time.now with Time.local(year,month,day) for other dates.
Formats:
%U - Week number of the year, starting with the first Sunday as the first day of the first week (00..53)
%V - Week number of year according to ISO-8601 (01..53)
%W - Week number of the year, starting with the first Monday as the first day of the first week (00..53)
Go
1
year, week := time.Now().ISOWeek()
Linux/Unix shell (bash)
1
date +%V
Returns the ISO-8601 week number.
Other formats under 'Ruby'. More details in the Linux Programmer's Manual
Lua
1
Current_week = os.date("%V")
Formats: see formats under 'Ruby'.
Windows PowerShell
1 2 3 4
Get-Date -UFormat %V # or "{0:d2}" -f ($(Get-Culture).Calendar.GetWeekOfYear($(Get-Date), [System.Globalization.CalendarWeekRule]::FirstFourDayWeek, [DayOfWeek]::Monday))
X++ (Microsoft Dynamics AX)
1 2
int weeknum; weeknum = weekOfYear(today());
C/AL (Microsoft Dynamics NAV)
1
MESSAGE(FORMAT(CALCDATE('CW', TODAY), 0, '<week>'));