• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 356
  • Last Modified:

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

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
marcypark
Asked:
marcypark
  • 7
  • 3
  • 2
  • +4
1 Solution
 
YuriPutivskyCommented:
// 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
 
marcyparkAuthor Commented:
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
 
YuriPutivskyCommented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
marcyparkAuthor Commented:
I am not sure I follow your code.  I'm sorry, I'm a newbie to this.
0
 
YuriPutivskyCommented:
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
 
marcyparkAuthor Commented:
I am using VB 6.0 and I think I should maybe use a pointer?
0
 
AxterCommented:
>>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
 
marcyparkAuthor Commented:
yes sorry VC++
0
 
AxterCommented:
Is your project an MFC program or Win32?
0
 
marcyparkAuthor Commented:
win32 console application
0
 
DanRollinsCommented:
Does the professor require that you use pointers in this homework?
0
 
marcyparkAuthor Commented:
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
 
marcyparkAuthor Commented:
Can someone help me?
0
 
void_mainCommented:
...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
 
tinchosCommented:
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
 
moduloCommented:
PAQed - no points refunded (of 500)

modulo
Community Support Moderator
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

  • 7
  • 3
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now