Solved

Create date with format MMDDYYhhmmss

Posted on 2004-03-24
5
788 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

751 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