In Javascript you can use this:

getWeekDay = function (year) {
  var d = new Date(); 
  d.setFullYear(year,0,1);
  return d.getDay()+1;
};

document.write(getWeekDay(2011));

Result is 1..7, as requested.

Answer from phlogratos on Stack Overflow
🌐
Cprogramming
cboard.cprogramming.com › c-programming › 149591-how-do-i-get-first-day-week-current-locale.html
How do I get the first day of the week for the current locale?
Check the man pages for further functionality; you will need to run it for other locale features too before querying them. After thatis done, *(char *)nl_langinfo(_NL_TIME_FIRST_WEEKDAY); yields the first day of week (1 for Sunday, 2 for Monday, .., 7 for Saturday), and *(char *)nl_langinf...
🌐
Statology
statology.org › home › how to get first day of week in excel (with examples)
How to Get First Day of Week in Excel (With Examples)
May 30, 2023 - Formula 1: Get First Day of Week (Assuming First Day is Sunday) ... Both formulas assume that cell A2 contains the date you’d like to find the first day of the week for.
🌐
Peug
peug.net › home › getting the first day in a week with c#
Getting the first day in a week with C# - Blog of Christophe Peugnet
March 17, 2023 - Well, there are no good answers for me. And the following code using simply DateTime.FirstDayOfWeek, finally returns me Sunday. ... My need is to give him the day of the month and he returns the number of the first day of the week.
🌐
Stack Overflow
stackoverflow.com › questions › 11426836 › how-to-get-first-day-of-week-in-c
time - How to get first day of week in c - Stack Overflow
You can create a config file containing a map of locale and first day of the week. Read this config file and create a look up table at the beginning of the program. Refer to this table everytime you are trying to get the first day of the week ...
🌐
Code Maze
code-maze.com › home › get the date of the first day in a week given the week number and a year in c#
Get the Date of the First Day In a Week Given ...
March 9, 2024 - Lastly, we multiply weekNumber by seven to calculate the number of days from the first Thursday to the specified week’s Thursday. But since our goal is to find the first Monday, we need to subtract 3 from this total. With that calculation done, we can compute a new DateTime object by adding this total to firstThursdayOfYear. For example, when we pass the year 2020 and week one as parameters to our method: Is this material useful to you? Consider subscribing and get ASP.NET Core Web API Best Practices eBook for FREE!
Top answer
1 of 16
34

As reported also by Wikipedia, in 1990 Michael Keith and Tom Craver published an expression to minimise the number of keystrokes needed to enter a self-contained function for converting a Gregorian date into a numerical day of the week.

The expression does preserve neither y nor d, and returns a zero-based index representing the day, starting with Sunday, i.e. if the day is Monday the expression returns 1.

A code example which uses the expression follows:

int d    = 15   ; //Day     1-31
int m    = 5    ; //Month   1-12`
int y    = 2013 ; //Year    2013` 

int weekday  = (d += m < 3 ? y-- : y - 2, 23*m/9 + d + 4 + y/4- y/100 + y/400)%7;  

The expression uses the comma operator, as discussed in this answer.

Enjoy! ;-)

2 of 16
20

A one-liner is unlikely, but the strptime function can be used to parse your date format and the struct tm argument can be queried for its tm_wday member on systems that modify those fields automatically (e.g. some glibc implementations).

int get_weekday(char * str) {
  struct tm tm;
  memset((void *) &tm, 0, sizeof(tm));
  if (strptime(str, "%d-%m-%Y", &tm) != NULL) {
    time_t t = mktime(&tm);
    if (t >= 0) {
      return localtime(&t)->tm_wday; // Sunday=0, Monday=1, etc.
    }
  }
  return -1;
}

Or you could encode these rules to do some arithmetic in a really long single line:

  • 1 Jan 1900 was a Monday.
  • Thirty days has September, April, June and November; all the rest have thirty-one, saving February alone, which has twenty-eight, rain or shine, and on leap years, twenty-nine.
  • A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400.

EDIT: note that this solution only works for dates after the UNIX epoch (1970-01-01T00:00:00Z).

🌐
Stack Overflow
stackoverflow.com › questions › 35215423
c - Calculate first day of a calendar week - Stack Overflow
Step four is subtract the largest fitting multiple of 7; I have created an array on the top. Then I need to subtract 1 from our 25% value given that a year that is entered is a leap year. I have included all I have got for my code right now. Any input would be greatly appreciated! Edit: I have fixed my for loop and spent some time on going over my code and I am just stuck on when I try to output the day with "d[ypercent] I get a bunch of jumbled up characters.
🌐
Codeforwin
codeforwin.org › home › c program to enter week number and print day of week
C program to enter week number and print day of week - Codeforwin
July 20, 2025 - Logic to convert week number to day of week in C programming. ... Step by step descriptive logic to print day name of week. Input week day number from user. Store it in some variable say week. Print Monday if(week == 1). I have assumed Monday as first day of week.
Find elsewhere
🌐
Quora
quora.com › How-do-I-write-a-C-program-to-print-the-day-of-the-week-by-getting-the-date-as-the-input-from-the-user-and-print-the-day-of-the-week
How to write a C program to print the day of the week by getting the date as the input from the user and print the day of the week - Quora
Answer (1 of 3): I am just giving you the function that you can add in your C program to get therequied output: [code]int get_weekday(char * str) { struct tm tm; if (strptime(str, "%d-%m-%Y", &tm) != NULL) { time_t t = mktime(&tm); return localtime(&t)->tm_wday; // Sunday=0, Monday=1, etc....
Top answer
1 of 2
2

Note: Not tested, but given the current year, this should do it:

const char *months[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep",
                        "Oct","Nov","dec","Jan"};
/* Start with January 1st of the current year */
struct tm curYear={
  0, // secs
  0, // mins
  0, // hours
  1, // Day of month
  0, // Month (Jan)
  year,
  0, // wday
  0, // yday
  0}; // isdst

/* Offset the number of weeks specified */
time_t secsSinceEpoch=mktime(&curYear)+
                      weekNum*86400*7; /* Shift by number of weeks */
struct tm *candidateDate=gmtime(&secsSinceEpoch);

/* If the candidate date is not a Monday, shift it so that it is */
if (candidateDate->tm_wday!=1)
{
  secsSinceEpoch+=(86400*(candidateDate->tm_wday-1)); 
  candidateDate=gmtime(&secsSinceEpoch);
}

printf("Mon %s %d",months[candidateDate->tm_mon],candidateDate->tm_mday\n");

You may have to adjust the formulas in this code depending on what exactly you mean by week 43 of a given year or to conform with ISO-8601, for example. However, this should present you with good boiler plate code to get started. You may also want to parameterize the day of the week, so that it is not hard coded.

Also, if you want, you can avoid the months array and having to format the time, by truncating the result of the ctime function, which just so happens to display more than you asked for. You would pass to it a pointer to the secsSinceEpoch value and truncate its output to just display the day of the week, the day of the month and the abbreviation of the months name.

2 of 2
2

The mktime function can do this. Simply initialize struct tm foo to represent the first day of the year (or first day of the first week of the year, as needed), then set tm_hour to 24*7*weeknum and call mktime. It will normalize the date for you.

Top answer
1 of 1
1

Specifying the first day of the first week manually

You can use pgfcalendar to store the first day of your first week in a LaTeX counter and use that later as the base for an offset.

With \setStartDate you set the first day of your first week and the \getDateOfWeek{<week>}{<offset>} will define \Year, \Month, \Day with the date that is in the <week>th week with an additional <offset>.

For example:

\setStartDate{2022-10-10}

sets the first week to start on October 10th, 2022.

With

\getDateOfWeek{1}{4}

you'll get October 14th and with

\getDateOfWeek{2}{0}

you'll get October 17th in \Month and \Day.

Code

\documentclass{article}
\usepackage{pgfcalendar}
\newcounter{myStartDate}
\makeatletter
\newcommand*{\setStartDate}[1]{% for week 1
  \begingroup
    \pgfcalendardatetojulian{#1}{\@tempcnta}%
    \setcounter{myStartDate}{\@tempcnta}%
  \endgroup
}
\newcommand*{\getDateOfWeek}[2]{%
  \begingroup
    \@tempcnta=\inteval{(#1-1)*7+#2}\relax
    \advance\@tempcnta by \c@myStartDate
    \edef\@temp{\endgroup\noexpand\pgfcalendarjuliantodate{\the\@tempcnta}}%
    \@temp{\Year}{\Month}{\Day}%
}
\makeatother
\usepackage{pgffor}
\begin{document}
\setStartDate{2022-01-03}
\foreach \week in {1,...,52}{
  Week \week\ goes from \getDateOfWeek{\week}{0}\Month/\Day\ to
                        \getDateOfWeek{\week}{4}\Month/\Day.\par}
\end{document}

Output

Using the actual week numbers of the years.

With the pgfcalendar-ext package of my tikz-ext package which incorporates another answer of mine and uses the week numbering according to ISO 8601 which mainly means that a new week starts on Monday.

Here's a solution with

\getTwoDaysOfWeek[<year>]{<week>}{<offset>}
  {<year>}{<month>}{<day>}{<offset year>}{<offset month>}{<offset day>}

which defines six macros (the argments on the second line) for you which contain

  • the first day of <week> of <year> and
  • the day that's <offset> after the first day of <week> of <year>.

The <year> argument is optionally, the default is the current year.

Code

\documentclass{article}
\usepackage{pgfcalendar-ext}
\newcommand*{\stripZero}[1]{\if0#1\else#1\fi}
\makeatletter
\newcommand*{\getTwoDaysOfWeek}[9][\the\year]{%
  % #1 = year (defaults to current year)
  % #2 = week number, #3 = offset
  % #4/#5/#6 = start year/month/day
  % #7/#8/#9 = end year/month/day
  \begingroup
    \pgfcalendardatetojulian{#1-01-01}{\@tempcnta}%
    \pgfcalendarjuliantoweekday{\@tempcnta}{\@tempcntb}%
    \edef\@dateStartWeek{\the\numexpr\@tempcnta-\@tempcntb+#2*7-7\relax}%
    \pgfcalendarjulianyeartoweek{\@tempcnta}{#1}{\@tempcntb}%
    \ifnum\@tempcntb>1
      % This is the last week of the previous year
      \edef\@dateStartWeek{\the\numexpr\@dateStartWeek+7\relax}%
    \fi
    \edef\@temp{\endgroup%
      \noexpand\pgfcalendarjuliantodate
        {\@dateStartWeek}{\noexpand#4}{\noexpand#5}{\noexpand#6}%
      \noexpand\pgfcalendarjuliantodate
        {\the\numexpr\@dateStartWeek+#3\relax}{\noexpand#7}{\noexpand#8}{\noexpand#9}}%
  \@temp
}
\makeatother
\newcommand*{\weekCell}[2][\the\year]{%
  \begin{tabular}[t]{@{}l@{}}Week #2:\\
    \getTwoDaysOfWeek[#1]{#2}{4}{\y}{\m}{\d}{\Y}{\M}{\D}%
    \stripZero\m/\stripZero\d--\stripZero\M/\stripZero\D
  \end{tabular}}

\usepackage{pgffor}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{lll}
\toprule
Time & Content & Note \\\midrule
\weekCell{1} & Content 1 & Note 1 \\
\weekCell{2} & Content 2 & Note 2 \\
\dots & \dots & \dots \\\bottomrule
\end{tabular}
\end{document}

Output

🌐
Qlik Community
community.qlik.com › t5 › Visualization-and-Usability › Find-first-day-of-week-number › td-p › 2455941
Solved: Find first day of week number - Qlik Community - 2455941
June 10, 2024 - Please LIKE threads if the provided solution is helpful to. ** ... Ditto - same here! ... In Qlik WeekStart() function does not allow directly entering a week number and a year without an actual date.
🌐
Bubble
forum.bubble.io › need help
How to extract the first day (and the last day) of a given week number - Need help - Bubble Forum
July 22, 2022 - Hello to all, Im looking for a way to extract the first day date and the last day date of a week. For exemple, we are the week 30, I would like to be able to get the Monday 18th and the Sunday 24th. Thank you in advan…
🌐
W3Resource
w3resource.com › csharp-exercises › datetime › csharp-datetime-exercise-52.php
C# - Find the first day of a week against a given date
January 26, 2026 - using System; // Importing the System namespace class dttimeex52 // Declaring a class named dttimeex52 { static void Main() // Declaring the Main method { int yr, mn, dt; // Declaring variables for year, month, and day Console.Write("\n\n Find the first day of a week against a given date :\n"); // Displaying a message in the console Console.Write("--------------------------------------------------------\n"); // Displaying a separator line // Input prompts for day, month, and year Console.Write(" Input the Day : "); dt = Convert.ToInt32(Console.ReadLine()); Console.Write(" Input the Month : ");
🌐
Rosetta Code
rosettacode.org › wiki › Day_of_the_week
Day of the week - Rosetta Code
February 13, 2026 - D R2,=F'7' w=(d+(m+1)*26/10+r+r/4+l/4+5*l)//7 C R2,=F'1' if w=1 (sunday) BNE WNE1 then XDECO R6,PG edit year XPRNT PG,12 print year WNE1 LA R6,1(R6) year=year+1 B LOOP next year ELOOP BR R14 exit PG DS CL12 buffer YREGS END DOW ... report zday_of_week data: lv_start type i value 2007, lv_n type i value 114, lv_date type sy-datum, lv_weekday type string, lv_day type c, lv_year type n length 4.
🌐
Wikipedia
en.wikipedia.org › wiki › Week
Week - Wikipedia
2 days ago - Most of Europe, China, West and Central Africa, and Oceania count Monday as the first day of the week, while much of America, South and Southeast Asia, and southern Africa count Sunday as the first day of the week. Most Arabic- and Persian-speaking countries use Saturday as the first day of the week, though some use Monday (Lebanon, Morocco, Tunisia and Tajikistan) or Sunday (Saudi Arabia and Yemen).