Epoch Converter Menu

What's the Current Week Number?

This week is ...

 

Week 36

Week 36 is from Monday August 31, 2015 until (and including) Sunday September 6, 2015.

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'). The highest week number in a year is either 52 or 53. This year has 53 weeks.

Lists of week numbers by year : 2014 - 2015 - 2016 - 2017 ...

Programming routines

Microsoft Excel

 =WEEKNUM(TODAY(),21)

Where the return type '21' is ISO-8601 (week starting on Monday).
In Excel 2007 try WEEKNUM(TODAY(),2) (2=week starting Monday). Just WEEKNUM(TODAY()) will show the weeknumber with weeks starting on Sunday (return type = 1).

PHP

$weekNumber = date("W"); 

or date("W", epoch) for other week numbers. Remember to use capital 'W' not 'w'.

Python

datetime.date.today().isocalendar()[1]

PERL

my $weekNumber = POSIX::strftime("%V", gmtime time);

Replace time with other epoch/UNIX timestamps for other week numbers.

Java

Calendar now = Calendar.getInstance();
now.get(Calendar.WEEK_OF_YEAR);

Use WEEK_OF_YEAR in the Calendar class.
More info on Stack Overflow

C#

DateTime test_date = DateTime.Now;
double week_of_year = Math.Ceiling(Convert.ToDouble(test_date.DayOfYear) / 7);

MySQL

SELECT WEEKOFYEAR(NOW())

Replace now() with other dates eg. SELECT WEEKOFYEAR('2008-02-20');
(You can also use the WEEK function with mode=3 select week(now(),3))

PostgreSQL

SELECT * FROM EXTRACT(WEEK from current_date())

MS SQL

SELECT DATEPART( wk, GETDATE() )

Oracle

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)

iPhone/Mac

[NSString stringWithFormat:@"Week %d", 
  [calendar ordinalityOfUnit:NSWeekCalendarUnit inUnit:NSYearCalendarUnit forDate:date]]; 

iPhone/iOS/Swift

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

lubridate::week()

Ruby

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)

Linux/Unix shell

date +%V 

Returns the ISO-8601 week number.
Other formats under 'Ruby'. More details on Kernel.org

Lua

Current_week = os.date("%V")

Formats: see formats under 'Ruby'.

PowerShell

Get-Date -UFormat %V 

X++ (Microsoft Dynamics AX)

int weeknum;
weeknum = weekOfYear(today());

C/AL (Microsoft Dynamics NAV):

MESSAGE(FORMAT(CALCDATE('CW', TODAY), 0, '<week>'));

 
Thanks to everyone who sent me corrections and updates!
Also see: Current day number


Comments and questions

blog comments powered by Disqus

Pages

Date and Time
Calculate difference
   between two dates

Week numbers
Weeks by year
Day numbers
Days by year

More
Comments & questions
Este sitio en Español
Related cookbooks
Unicode Tools
Character Set Tools



Follow us