Convert Custom String in to Date Format (mmmm dd, yyyy)
-
Hi.. All I m Working on one of Text-correction module .. I have some difficulty in conversion of the various form of Date come in to raw-input text to some Standard format(mmmm dd yyyy). various possibilty of Date text are: input OutPut Jan 5th 2005 = January 5, 2005 Jan 2605 = January 26, 2005 Jan of 05 = January 2005 Jan 05 = January 2005 6th of June = June 6, 2005 or June 6 6th of June 05= June 6, 2005 this month 6th = July 6, 2005 On 6th of this month = June 6, 2005 or only number like max-digit(i.e: 06242005) = output Reqired is : mm/dd/yyyy =06/24/2005 to min-digit (i.e : 625) = = output Reqired is : mm/dd/yyyy =06/2/2005 Can any one Guide me ... how I can Do...it.. I m very much confused ?? for the logic.... can any MFC class help here ? CDateTime , CDateTimeFormatInfo ???? pls...Help me ... looking for positive reply form all of u ! thanks in Advance !! Rajan Kapadia
-
Hi.. All I m Working on one of Text-correction module .. I have some difficulty in conversion of the various form of Date come in to raw-input text to some Standard format(mmmm dd yyyy). various possibilty of Date text are: input OutPut Jan 5th 2005 = January 5, 2005 Jan 2605 = January 26, 2005 Jan of 05 = January 2005 Jan 05 = January 2005 6th of June = June 6, 2005 or June 6 6th of June 05= June 6, 2005 this month 6th = July 6, 2005 On 6th of this month = June 6, 2005 or only number like max-digit(i.e: 06242005) = output Reqired is : mm/dd/yyyy =06/24/2005 to min-digit (i.e : 625) = = output Reqired is : mm/dd/yyyy =06/2/2005 Can any one Guide me ... how I can Do...it.. I m very much confused ?? for the logic.... can any MFC class help here ? CDateTime , CDateTimeFormatInfo ???? pls...Help me ... looking for positive reply form all of u ! thanks in Advance !! Rajan Kapadia
-
Hi.. All I m Working on one of Text-correction module .. I have some difficulty in conversion of the various form of Date come in to raw-input text to some Standard format(mmmm dd yyyy). various possibilty of Date text are: input OutPut Jan 5th 2005 = January 5, 2005 Jan 2605 = January 26, 2005 Jan of 05 = January 2005 Jan 05 = January 2005 6th of June = June 6, 2005 or June 6 6th of June 05= June 6, 2005 this month 6th = July 6, 2005 On 6th of this month = June 6, 2005 or only number like max-digit(i.e: 06242005) = output Reqired is : mm/dd/yyyy =06/24/2005 to min-digit (i.e : 625) = = output Reqired is : mm/dd/yyyy =06/2/2005 Can any one Guide me ... how I can Do...it.. I m very much confused ?? for the logic.... can any MFC class help here ? CDateTime , CDateTimeFormatInfo ???? pls...Help me ... looking for positive reply form all of u ! thanks in Advance !! Rajan Kapadia
Have a look at COleDateTime class as well. Steve Mayfield: "Coding in VB is like riding a tricycle...once you figured out how to peddle, its really hard to fall off." My Articles
-
CDateTimeCtrl::SetFormat[^] might be able to help you.
- Nilesh "Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
Thanks for u r Reply... But I have clearly mention that ... My problem is Parsing the "ambigous" String not the Formating the Date. If I can find the Proper input the Any Constructer of MFC class (like , COLEDateTime, CDateTime , CDateTimeFormatINfo,,... ) then I can Convert to any format of date!! But My Problem is how to find parse the input Nummeric?? i.e: only number like max-digit(i.e: 06242005) = output Reqired is : mm/dd/yyyy =06/24/2005 to min-digit (i.e : 625) = = output Reqired is : mm/dd/yyyy =06/2/2005. Can u help me for this ???
-
Hi.. All I m Working on one of Text-correction module .. I have some difficulty in conversion of the various form of Date come in to raw-input text to some Standard format(mmmm dd yyyy). various possibilty of Date text are: input OutPut Jan 5th 2005 = January 5, 2005 Jan 2605 = January 26, 2005 Jan of 05 = January 2005 Jan 05 = January 2005 6th of June = June 6, 2005 or June 6 6th of June 05= June 6, 2005 this month 6th = July 6, 2005 On 6th of this month = June 6, 2005 or only number like max-digit(i.e: 06242005) = output Reqired is : mm/dd/yyyy =06/24/2005 to min-digit (i.e : 625) = = output Reqired is : mm/dd/yyyy =06/2/2005 Can any one Guide me ... how I can Do...it.. I m very much confused ?? for the logic.... can any MFC class help here ? CDateTime , CDateTimeFormatInfo ???? pls...Help me ... looking for positive reply form all of u ! thanks in Advance !! Rajan Kapadia
Break the inputs down into what they are/aren't like:
if (first_3_letters_are_a_month)
{
Jan 5th 2005 = January 5, 2005
Jan 2605 = January 26, 2005
Jan of 05 = January 2005
Jan 05 = January 2005
}
else
{
if (first_word_is_this)
this month 6th = July 6, 2005
else if (first_word_is_on)
On 6th of this month = June 6, 2005
else // must start with a number
{
if (first_word_has_th)
{
6th of June = June 6, 2005 or June 6
6th of June 05= June 6, 2005
}
else
{
06242005 = 06/24/2005
625 = 06/2/2005
}
}
}Now you should have an easier time parsing them.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
Break the inputs down into what they are/aren't like:
if (first_3_letters_are_a_month)
{
Jan 5th 2005 = January 5, 2005
Jan 2605 = January 26, 2005
Jan of 05 = January 2005
Jan 05 = January 2005
}
else
{
if (first_word_is_this)
this month 6th = July 6, 2005
else if (first_word_is_on)
On 6th of this month = June 6, 2005
else // must start with a number
{
if (first_word_has_th)
{
6th of June = June 6, 2005 or June 6
6th of June 05= June 6, 2005
}
else
{
06242005 = 06/24/2005
625 = 06/2/2005
}
}
}Now you should have an easier time parsing them.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
Thanks for u r Reply sir. But ..still here my patterns are not static ( u assumed by mistake ) my patterns may vary due to human tendecies to speck every time different patterns for the same thing !! so.....I can't make the code based on pre-assumption like u !! Currently , I m doing the Ambigious rule making for the Text-correction.. But , I m still confused at parsing the only Numbers string ( how to differnceate with numbers for Day,Month,Year...! Can i make Regular Expression to validate the input numbers in to Day, Month, Year? Can u assist me ? Cheers, Rajan Kapadia :)
-
Thanks for u r Reply sir. But ..still here my patterns are not static ( u assumed by mistake ) my patterns may vary due to human tendecies to speck every time different patterns for the same thing !! so.....I can't make the code based on pre-assumption like u !! Currently , I m doing the Ambigious rule making for the Text-correction.. But , I m still confused at parsing the only Numbers string ( how to differnceate with numbers for Day,Month,Year...! Can i make Regular Expression to validate the input numbers in to Day, Month, Year? Can u assist me ? Cheers, Rajan Kapadia :)
Anonymous wrote: But , I m still confused at parsing the only Numbers string ( how to differnceate with numbers for Day,Month,Year...! How about:
CString strDate;
if (strDate.GetLength() == 8) // e.g., 06242005
{
nMonth = atoi(strDate.Left(2));
nDay = atoi(strDate.Mid(2, 2));
nYear = atoi(strDate.Right(4));
}
else if (strDate.GetLength() == 3) // e.g., 625
{
nMonth = atoi(strDate.Left(1));
nDay = atoi(strDate.Mid(1, 1));
nYear = atoi(strDate.Right(1)); // might want to add 2000
}
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
Anonymous wrote: But , I m still confused at parsing the only Numbers string ( how to differnceate with numbers for Day,Month,Year...! How about:
CString strDate;
if (strDate.GetLength() == 8) // e.g., 06242005
{
nMonth = atoi(strDate.Left(2));
nDay = atoi(strDate.Mid(2, 2));
nYear = atoi(strDate.Right(4));
}
else if (strDate.GetLength() == 3) // e.g., 625
{
nMonth = atoi(strDate.Left(1));
nDay = atoi(strDate.Mid(1, 1));
nYear = atoi(strDate.Right(1)); // might want to add 2000
}
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
Thanks for u r reply.... I have done same thing ... just 2-day before... I have written various RE for classifying Input String in to DATE Formats based on it length. one of possible RE u can see : for 8-digit string : ((^(?10|12|0?[13578])(?3[01]|[12][0-9]|0?[1-9])(?(1[8-9]\\d{2})|([2-9]\\d{3}))$)|(^(?11|0?[469])(?30|[12][0-9]|0?[1-9])(?(1[8-9]\\d{2})|([2-9]\\d{3}))$)|(^(?0?2)(?2[0-8]|1[0-9]|0?[1-9])(?(1[8-9]\\d{2})|([2-9]\\d{3}))$)|(^(?0?2)(?29)(?[2468][048]00)$)|(^(?0?2)(?29)(?[3579][26]00)$)|(^(?0?2)(?29)(?[1][89][0][48])$)|(^(?0?2)(?29)(?[2-9][0-9][0][48])$)|(^(?0?2)(?29)(?[1][89][2468][048])$)|(^(?0?2)(?29)(?[2-9][0-9][2468][048])$)|(^(?0?2)(?29)(?[1][89][13579][26])$)|(^(?0?2)(?29)(?[2-9][0-9][13579][26])$)) This way I have solved my proble ......is it write-way to do it ??? and I want to ask? how to parse the Unkown or Ambigous pattern ....like ? "on 10th of this month" ----> so I want to find the current system date whenever I found word "this" !!!! is It?? Can I do similar for "next", "previous" ...words???? and for Day,Month,Year ?? can u assist in this similar type of problem ??? Cheers, Rajan Kapadia :)
-
Thanks for u r reply.... I have done same thing ... just 2-day before... I have written various RE for classifying Input String in to DATE Formats based on it length. one of possible RE u can see : for 8-digit string : ((^(?10|12|0?[13578])(?3[01]|[12][0-9]|0?[1-9])(?(1[8-9]\\d{2})|([2-9]\\d{3}))$)|(^(?11|0?[469])(?30|[12][0-9]|0?[1-9])(?(1[8-9]\\d{2})|([2-9]\\d{3}))$)|(^(?0?2)(?2[0-8]|1[0-9]|0?[1-9])(?(1[8-9]\\d{2})|([2-9]\\d{3}))$)|(^(?0?2)(?29)(?[2468][048]00)$)|(^(?0?2)(?29)(?[3579][26]00)$)|(^(?0?2)(?29)(?[1][89][0][48])$)|(^(?0?2)(?29)(?[2-9][0-9][0][48])$)|(^(?0?2)(?29)(?[1][89][2468][048])$)|(^(?0?2)(?29)(?[2-9][0-9][2468][048])$)|(^(?0?2)(?29)(?[1][89][13579][26])$)|(^(?0?2)(?29)(?[2-9][0-9][13579][26])$)) This way I have solved my proble ......is it write-way to do it ??? and I want to ask? how to parse the Unkown or Ambigous pattern ....like ? "on 10th of this month" ----> so I want to find the current system date whenever I found word "this" !!!! is It?? Can I do similar for "next", "previous" ...words???? and for Day,Month,Year ?? can u assist in this similar type of problem ??? Cheers, Rajan Kapadia :)
Rajan Kapadia wrote: ...is it write-way to do it ??? My first response would be no. Since there are only six possibilities, using an
if
/else
construct would be much simpler now and in the future if you or someone else needed to modify it. Rajan Kapadia wrote: I want to find the current system date... That is whattime()
is for.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
Rajan Kapadia wrote: ...is it write-way to do it ??? My first response would be no. Since there are only six possibilities, using an
if
/else
construct would be much simpler now and in the future if you or someone else needed to modify it. Rajan Kapadia wrote: I want to find the current system date... That is whattime()
is for.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
Thanks for u r reply.... David Crow Wrote:: using an if/else construct would be much simpler now ??? means what is exact ....?? means ?? --> 8-3 Length string ?? for Current SystemDate I want to Know how i can do for "next","this", "previous" , etc words ?? ??? Cheers, Rajan Kapadia :)
-
Thanks for u r reply.... David Crow Wrote:: using an if/else construct would be much simpler now ??? means what is exact ....?? means ?? --> 8-3 Length string ?? for Current SystemDate I want to Know how i can do for "next","this", "previous" , etc words ?? ??? Cheers, Rajan Kapadia :)
Rajan Kapadia wrote: means what is exact ....?? means ?? --> 8-3 Length string ?? This is a very strange looking sentence, but I think what you are asking looks like this:
if (3 == length)
else if (4 == length)
else if (5 == length)
else if (6 == length)
else if (7 == length)
else if (8 == length)If that is not right, please ask again. Rajan Kapadia wrote: for Current SystemDate I want to Know how i can do for "next","this", "previous" , etc words ?? Like I indicated, today's date can be obtained using
time()
. Yesterday's date can be obtained by subtracting 86400 from that value, and tomorrow's date can be obtained by adding 86400 to that value. Make sense?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
Rajan Kapadia wrote: means what is exact ....?? means ?? --> 8-3 Length string ?? This is a very strange looking sentence, but I think what you are asking looks like this:
if (3 == length)
else if (4 == length)
else if (5 == length)
else if (6 == length)
else if (7 == length)
else if (8 == length)If that is not right, please ask again. Rajan Kapadia wrote: for Current SystemDate I want to Know how i can do for "next","this", "previous" , etc words ?? Like I indicated, today's date can be obtained using
time()
. Yesterday's date can be obtained by subtracting 86400 from that value, and tomorrow's date can be obtained by adding 86400 to that value. Make sense?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
Thanks for u r Reply ..... its good to see u that we r thinking same way...!! :-O For Only Number- parsing last time I have written , that I have written various Regular-Expression (RE) to parse the given length number in case statment !!! ( one of Example of RE for stringlen(8) I have given last time ) In Last Reply I have asked a'bt how to tekal words like : "this Month" , "this year", "Next Month","Next Year", "Previous Month", "Previous Year", Etc... Currently I m thinking in a way that, I m Extracting DAY,MONTH,YEAR from the given pattern and then I search for words (this, next, Previous)tide with DAY,MONTH,YEAR word and then from Current system date Extratcion of current DAY, MONTH , YEAR......I m incrementing (+1) or decremanting (-1) by one to corresponding DAY,MONTH,YEAR variable . But,conflict for "next " phares is when we r in Decemeber and "next month " phares occurs then we increment Year and set month to January ......similar problem for "Previous" phares at January month ...? :(:(( ........ Is It I m going right way in my path ? :confused: or .....any other good Idea :cool: ?? wait for u positive reply and then start implementing this Idea..... Cheers , Rajan Kapadia :)
-
Thanks for u r Reply ..... its good to see u that we r thinking same way...!! :-O For Only Number- parsing last time I have written , that I have written various Regular-Expression (RE) to parse the given length number in case statment !!! ( one of Example of RE for stringlen(8) I have given last time ) In Last Reply I have asked a'bt how to tekal words like : "this Month" , "this year", "Next Month","Next Year", "Previous Month", "Previous Year", Etc... Currently I m thinking in a way that, I m Extracting DAY,MONTH,YEAR from the given pattern and then I search for words (this, next, Previous)tide with DAY,MONTH,YEAR word and then from Current system date Extratcion of current DAY, MONTH , YEAR......I m incrementing (+1) or decremanting (-1) by one to corresponding DAY,MONTH,YEAR variable . But,conflict for "next " phares is when we r in Decemeber and "next month " phares occurs then we increment Year and set month to January ......similar problem for "Previous" phares at January month ...? :(:(( ........ Is It I m going right way in my path ? :confused: or .....any other good Idea :cool: ?? wait for u positive reply and then start implementing this Idea..... Cheers , Rajan Kapadia :)
Rajan Kapadia wrote: I m incrementing (+1) or decremanting (-1) by one to corresponding DAY,MONTH,YEAR variable . But,conflict for "next " phares is when we r in Decemeber and "next month " phares occurs then we increment Year and set month to January ......similar problem for "Previous" phares at January month ...? ........ Is It I m going right way in my path ? or .....any other good Idea ?? This is how I did it some eleven years ago. But since MFC has four date-related classes (I'm not sure if STL does or not), I would use them instead. There's no need to reinvent the wheel.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
Rajan Kapadia wrote: I m incrementing (+1) or decremanting (-1) by one to corresponding DAY,MONTH,YEAR variable . But,conflict for "next " phares is when we r in Decemeber and "next month " phares occurs then we increment Year and set month to January ......similar problem for "Previous" phares at January month ...? ........ Is It I m going right way in my path ? or .....any other good Idea ?? This is how I did it some eleven years ago. But since MFC has four date-related classes (I'm not sure if STL does or not), I would use them instead. There's no need to reinvent the wheel.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
This is how I did it some eleven years ago. But since MFC has four date-related classes (I'm not sure if STL does or not), I would use them instead. There's no need to reinvent the wheel. I m not Understanding ..? can u Explain me in Deep?? As Mention preiously that how i can code perticular Pattern like this ::: " Next year 10th of January " ------> "Next Year [Day](th)* (of) [Month]" (I m parsing using this rule) and initilize the DataTime strucure with parsed Day,Month and missing term Year with Current System Year with (+/-) corresponding to words like " previous, next, this" phrases. Replacement pattern is : [Month] [Day], [CurrentSystemYear] can I stic to this type of staic parsing ?:zzz: Is it write way to do it ?:confused: Waits for u r reply!!:-D Cheers, Rajan Kapadia :)
-
This is how I did it some eleven years ago. But since MFC has four date-related classes (I'm not sure if STL does or not), I would use them instead. There's no need to reinvent the wheel. I m not Understanding ..? can u Explain me in Deep?? As Mention preiously that how i can code perticular Pattern like this ::: " Next year 10th of January " ------> "Next Year [Day](th)* (of) [Month]" (I m parsing using this rule) and initilize the DataTime strucure with parsed Day,Month and missing term Year with Current System Year with (+/-) corresponding to words like " previous, next, this" phrases. Replacement pattern is : [Month] [Day], [CurrentSystemYear] can I stic to this type of staic parsing ?:zzz: Is it write way to do it ?:confused: Waits for u r reply!!:-D Cheers, Rajan Kapadia :)
Rajan Kapadia wrote: I m not Understanding ..? can u Explain me in Deep?? Instead of doing this:
void IncrementDay( int &nMonth, int &nDay, int &nYear )
{
nDay++;
if (nDay > DaysInMonth(nMonth, nYear))
{
nDay = 1;nMonth++; if (nMonth > 12) { nMonth = 1; nYear++; } }
}
Do something like this instead:
CTime today = CTime::GetCurrentTime();
CTimeSpan oneDay(1, 0, 0, 0);
CTime tomorrow = today + oneDay;
CTime yesterday = today - oneDay;Simpler?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
Rajan Kapadia wrote: I m not Understanding ..? can u Explain me in Deep?? Instead of doing this:
void IncrementDay( int &nMonth, int &nDay, int &nYear )
{
nDay++;
if (nDay > DaysInMonth(nMonth, nYear))
{
nDay = 1;nMonth++; if (nMonth > 12) { nMonth = 1; nYear++; } }
}
Do something like this instead:
CTime today = CTime::GetCurrentTime();
CTimeSpan oneDay(1, 0, 0, 0);
CTime tomorrow = today + oneDay;
CTime yesterday = today - oneDay;Simpler?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
this one is simpler ....but how to takel with Month & Year ....increment ....No constructor for which give us month and year initilization.( we can't sent timeticks also ....i.e 30|31 * oneDaytime or 365|366 * onedaytime ) How i can Do increment & decremant Month & Year Now from U r Way ! U make me more confuse by giveing this idea!:laugh: also, how u think a'bt my Search-Replace Rule Idea ?:rolleyes: Wait for u r reply here !! :cool: Cheers , Rajan Kapadia :)
-
this one is simpler ....but how to takel with Month & Year ....increment ....No constructor for which give us month and year initilization.( we can't sent timeticks also ....i.e 30|31 * oneDaytime or 365|366 * onedaytime ) How i can Do increment & decremant Month & Year Now from U r Way ! U make me more confuse by giveing this idea!:laugh: also, how u think a'bt my Search-Replace Rule Idea ?:rolleyes: Wait for u r reply here !! :cool: Cheers , Rajan Kapadia :)
Rajan Kapadia wrote: How i can Do increment & decremant Month... By knowing how many days are in each month. If today is July 27th, 2005 and I wanted to advance one month, use:
CTime today = CTime::GetCurrentTime(); CTimeSpan oneMonth(31, 0, 0, 0); CTime nextMonth = today + oneMonth;
"One must learn from the bite of the fire to leave it alone." - Native American Proverb