Solved

Program to convert format from 12/1/1999 to December 1, 1999

Posted on 2003-11-10
16
344 Views
Last Modified: 2010-04-01
How can you convert a date in the format 07/21/1955 to something like July 21, 1955 by using pointers?  Help me out a little please :)
0
Comment
Question by:marcypark
  • 7
  • 3
  • 2
  • +4
16 Comments
 
LVL 4

Expert Comment

by:YuriPutivsky
ID: 9719427
// use COleDateTime class
COleDateTime convert;
// here we go...
if (!convert.ParseDateTime("07/21/1955", VAR_DATEVALUEONLY, LANG_USER_DEFAULT))
// error handler
    return;

// and back...
CString str = convert.Format("%B %d, %Y");
// str will looks like: July 21, 1955
0
 

Author Comment

by:marcypark
ID: 9719439
I need to use this format for any date entered; prompting the user to enter a date in the form mm/dd/yyyy and then printing it like month day, year.
0
 
LVL 4

Expert Comment

by:YuriPutivsky
ID: 9719454
So?
define a buffer - big enough
char buf[64];

// get user input here and populate buf
// then
// use COleDateTime class
COleDateTime convert;
// here we go...
if (!convert.ParseDateTime(buf, VAR_DATEVALUEONLY, LANG_USER_DEFAULT))
// error handler
    return;

// and back...
CString str = convert.Format("%B %d, %Y");
// here str contains what user printed in the new format
0
 

Author Comment

by:marcypark
ID: 9719479
I am not sure I follow your code.  I'm sorry, I'm a newbie to this.
0
 
LVL 4

Expert Comment

by:YuriPutivsky
ID: 9719519
OK,
Your question was how to convert user input data in "mm/dd/yyyy" format to the new format
 "Month dd, yyyy".
The answer you get a char buffer from user (how? this is another question)
Then using COleDateTime class you convert user input into suitable format.
Now you are reay to display the entered date in new format (how? again it depends what do you want to use).

1. cout << buf;
2. printf("%s", buf);
3. ....
0
 

Author Comment

by:marcypark
ID: 9719535
I am using VB 6.0 and I think I should maybe use a pointer?
0
 
LVL 30

Expert Comment

by:Axter
ID: 9719605
>>I am using VB 6.0 and I think I should maybe use a pointer?

Do you mean you're using VC++ 6.0????

This is the C++ topic area.  If you have a VB question, I recommend you post it in the Visual Basic topic area.

If you're coding in C++ please post what compiler you're using, and what type of project (MFC, Win32, UNIX, etc...)
0
 

Author Comment

by:marcypark
ID: 9719611
yes sorry VC++
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 30

Expert Comment

by:Axter
ID: 9719723
Is your project an MFC program or Win32?
0
 

Author Comment

by:marcypark
ID: 9719775
win32 console application
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9720868
Does the professor require that you use pointers in this homework?
0
 

Author Comment

by:marcypark
ID: 9721810
No, I'm sorry, I am suppose to use strings.  And it's not a homework assignment, it's a non-graded self-exercise.
0
 

Author Comment

by:marcypark
ID: 9725596
Can someone help me?
0
 
LVL 4

Expert Comment

by:void_main
ID: 9866270
...yes:

you have a string for the input like this:
char *originalDate = "12/07/2003";

then you have to parse the string like this:
int values[3];  // 0 is month   1 is day   2 is year
int where = 0; // Which value is processed now? 0 = month ......
int oldX = 0;   // internal for token parsing
char before;   // last token
for (int x = 0; x < strlen(originalDate); x++)
{
        if ((originalDate[x] == '/') || (originalDate[x] == 0))      // found a   /     or a \0 (string termination sign)
        {
            before = orignalDate[x];        // What delimeter we HAD
            originalDate[x] = 0;               // set it to zero (temp.)

            values[where] = atoi(originalDate + oldX);     // atoi means string to integer

            oldX = x + 1;                        // Store the last position we were
            where++;                             // each time we find a new token, we should go to the next variable

            originalDate[x] = before;       // replace the old token
        }
}

then you have to reformat the string, using a table like this:
char *months[12] = {"January", "February", "March", "April", ....., "December"};

finally you need a new buffer to write your results:
char newBuffer[100];
sprintf(newBuffer, "%s %i, %i", months[values[0] - 1], values[1], values[2]);
// note: %s is replaced by the String in monts i.e. "April"
//          %i is replaced by the Integer in values[1] and [2]   in order they are listed

now your buffer "newBuffer" contains "December 12, 2003" you can printf like this:
printf("%s\n", newBuffer);

IMPORTANT note: this is pseudocode. You also have to include the correct header-files for strlen and atoi
0
 
LVL 9

Expert Comment

by:tinchos
ID: 10248867
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ - no points refunded

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 10308083
PAQed - no points refunded (of 500)

modulo
Community Support Moderator
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

746 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now