?
Solved

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

Posted on 2003-11-10
16
Medium Priority
?
351 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
[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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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…
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.

719 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