Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,859 questions

51,780 answers

573 users

How to add N days to a date in C

1 Answer

0 votes
#include <stdio.h>
#include <time.h>

int main(void) {
    struct tm tm = { 0 };

    tm.tm_mon = 6 - 1; // 6 (June)
    tm.tm_mday = 11;
    tm.tm_year = 2022 - 1900; // 2022
    tm.tm_isdst = -1;

    int N = 14;
    tm.tm_mday += N;

    if (mktime(&tm) == -1)
        fprintf(stderr, "mktime failed");
    else	
        printf("%d/%d/%d", tm.tm_mon + 1, tm.tm_mday, tm.tm_year + 1900);

    return 0;
}




/*
run:

6/25/2022

*/

 



answered Jun 11, 2022 by avibootz

Related questions

1 answer 72 views
72 views asked Jun 14, 2022 by avibootz
1 answer 89 views
89 views asked Jun 13, 2022 by avibootz
1 answer 123 views
123 views asked Jun 12, 2022 by avibootz
1 answer 128 views
1 answer 176 views
176 views asked Sep 20, 2019 by avibootz
2 answers 210 views
210 views asked Nov 8, 2017 by avibootz
1 answer 184 views
...