Solved

Create date with format MMDDYYhhmmss

Posted on 2004-03-24
5
797 Views
Last Modified: 2007-12-19
I am trying to write data to a file with the name MMDDYYhhmmss.txt,
but cannot seem to store the date in a variable.  I am not sure where to start to get a date with that type of format.

Can someone help,

thanks,

jmsloan
0
Comment
Question by:jmsloan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 4

Expert Comment

by:bdunz19
ID: 10671498
declare a SYSTEMTIME variable then use GetLocalTime():

SYSTEMTIME stTime;

GetLocalTime(&stTime);

then use stTime.wDay, stTime.wMonth, ect.
0
 
LVL 4

Expert Comment

by:bdunz19
ID: 10671509
to use these variables and functions you must include windows.h.

Brandon
0
 
LVL 4

Expert Comment

by:bdunz19
ID: 10671575
CHAR      format[256];
INT      hour;
SYSTEMTIME stTime;
GetLocalTime(&stTime);

if(stTime.wHour > 12)
      hour = stTime.wHour - 12;
else
      hour = stTime.wHour;

sprintf(format, "%d/%d/%d %d:%d:%d", stTime.wMonth, stTime.wDay, stTime.wYear, hour, stTime.wMinute, stTime.wSecond);
printf("%s\n", format);
0
 
LVL 3

Author Comment

by:jmsloan
ID: 10671851
what about a 2 digit month?
0
 
LVL 8

Accepted Solution

by:
mnashadka earned 50 total points
ID: 10671967
You can use strftime a little easier, and also across platforms:
char var[30] = {0}; // Variable that will hold the data
time_t now = time(NULL);
struct tm *tm_data = localtime(&now);
strftime(var, 30, "%m%d%y%H%M%S", tm_data);

You need to #include <time.h> or <ctime> for these functions.  The strftime documentation has information about all kinds of different modifiers (am/pm, 4 digit year, etc) to use with the date.  Good luck.
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Suggested Courses

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question