Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3333244
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:46:31+00:00 2026-05-17T23:46:31+00:00

I have the current week as an integer (43 as of now). I need

  • 0

I have the current week as an integer (43 as of now).
I need the date for Monday in a format like ‘Mon Oct 25’.

Thought I could accomplish that by a function from but I don’t know how to do that.
Any suggestions?

EDIT:
I tried the suggestion from R., but it doesn’t give the expected result. Did I implement it wrong?

time_t monday;
char date_format[32];
time_t now = time(NULL);
struct tm *tm = localtime(&now);

tm->tm_yday = 0; // reset to Jan 1st
tm->tm_hour = 24 * 7 * WEEK + 24; // goto Sun and add 24h for Mon

monday = mktime(tm);

strftime(date_format, 31, "%a : %D", tm);

printf("%s\n", date_format);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:46:31+00:00Added an answer on May 17, 2026 at 11:46 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have week number of current year and week day generated by date() like
I have a problem getting the date of monday in the current week. echo
I'm trying to obtain the current week for date comparison in SQLite. I have
right now I have this pulling data for the current week, but the week
I have the current basic structure for each domain object that I need to
I have my current location fixed via CoreLocation. Now I want to get those
I have a current Date object that needs to be incremented by one day
I have the following loop to calculate the dates of the current week and
I have a crystal report that shows sales volumes called week to date volume.
I have a small game, where the leaders of the previous and current week

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.