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 8050467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:05:48+00:00 2026-06-05T07:05:48+00:00

I am currently working on a c project and I am trying to get

  • 0

I am currently working on a c project and I am trying to get the date from the system and build that into a string.

I am very new to c so I’m currently learning as I go along but I cannot get this to work. Below is the code that I have

time_t now = time(NULL);
struct tm *t = localtime(&now);
char currentDate[13];
char day[3];
char month[3];
char year[5];
char hour[3];
char min[3];
sprintf(day, "%02d", t->tm_mday, sizeof(day));
sprintf(month, "%02d", t->tm_mon+1, sizeof(month));
sprintf(year, "%04d", t->tm_year + 1900, sizeof(year));
sprintf(hour, "%02d", t->tm_hour, sizeof(hour));
sprintf(min, "%02d", t->tm_min, sizeof(min));
strcat(currentDate, day);
strcat(currentDate, month);
strcat(currentDate, year);
strcat(currentDate, hour);
strcat(currentDate, min);
printf("Current Date: %s", currentDate);

When it does the printf it just prints a load of rubbish e.g.

Current Date: ÃÃx·Z¤ÿ·øÃéôÃÿ·^XÃé<95>úþ·^F^FÃ^P^_

What am I doing wrong.

  • 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-06-05T07:05:50+00:00Added an answer on June 5, 2026 at 7:05 am

    I would consider using ctime and/or strftime. It might get you what you want without messing too much with strings and time fields.

    With strftime:

    char text[100];
    time_t now = time(NULL);
    struct tm *t = localtime(&now);
    
    
    strftime(text, sizeof(text)-1, "%d %m %Y %H:%M", t);
    printf("Current Date: %s", text);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Heya, I'm currently trying to get bltoolkit working in my project. I've added the
Currently, I'm trying to get the lib working in my project, but with no
I'm currently working on a project trying to update a page reading from an
I'm currently working on a ASP.Net 3.5 project and trying to implement session timeout
I'm currently working on a project using netbeans 6.9 and grails 1.3. I'm trying
So I'm working on my first big C# project and am currently trying to
I'm currently working on a project running on JBoss AS 7 that requires authentication
I'm currently working on a project that requires me to do some sampling with
I have been trying to get a working algorithm that detects intersection between a
For a project, I'm trying to send UDP packets from Linux kernel-space. I'm currently

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.