• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Newby's question: How do I assign the week number to a string literal?

Q&A Forum › Category: ESP32 › Newby's question: How do I assign the week number to a string literal?
0 Vote Up Vote Down
Tony Douglas asked 4 years ago

I’m working with code from the Web Servers course  3.4 – Web Server: Display Sensor Readings from File (Charts).  I have converted it to store readings on an SD card and now wish to rename the resulting file with the week number and year. I can print out the week number but can’t find out how to assign it to a string, so that I can concatenate it with the year.  The code that prints the week number is below (see bold type), but I need to assign the (&timeinfo, “%V”) part to a string literal.

 

Any ideas?

 
// Function that gets current epoch time
unsigned long getTime() {
  time_t now;
 
  struct tm timeinfo;
  if (!getLocalTime(&timeinfo)) {
    Serial.println(“Failed to obtain time”);
    return(0);
  }
  time(&now);
  currentTime = (time(&now) + gmtOffset_sec + daylightOffset_sec);
  Serial.print(“Week No. = “);
  Serial.println(&timeinfo, “%V”);
  return currentTime;
}

3 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi Tony.
See the example in this tutorial: https://randomnerdtutorials.com/esp32-date-time-ntp-client-server-arduino/ See the last part of the example code. It shows how to do that.
Let me know if you need further help.
Regards,
Sara
 

0 Vote Up Vote Down
Tony Douglas answered 4 years ago

Thanks Sara. Just what I needed. Thanks again for your great support.

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Great!
I’ll mark this question as resolved.
If you need further help, you just need to open a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

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.