| | |
C++ / MFC Date Validation
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Oct 2008
Posts: 35
Reputation:
Solved Threads: 1
Hi,
i just need to know is there any method in MFC / C++
which will do the validation for the entered date.
ie if the date 12/11/2008 is given as input it should return saying the date is valid.i hope there exsists some standard function.
it should also check for leap leap year,and wrong date such as 31/11/2008 etc. thanks in advance.
i just need to know is there any method in MFC / C++
which will do the validation for the entered date.
ie if the date 12/11/2008 is given as input it should return saying the date is valid.i hope there exsists some standard function.
it should also check for leap leap year,and wrong date such as 31/11/2008 etc. thanks in advance.
you could try the parsedate() member of COleDateTime:
I don't have MFC anymore, so I can't test it, but I'm sure it works somewhat like that. If this doesn't work you should have a look at the wxDateTime object from wxWidgets.
C++ Syntax (Toggle Plain Text)
if (!COleDateTime::ParseDateTime("12/11/2008") { // That's not a date bucko! }
I don't have MFC anymore, so I can't test it, but I'm sure it works somewhat like that. If this doesn't work you should have a look at the wxDateTime object from wxWidgets.
Last edited by niek_e; Nov 21st, 2008 at 9:34 am.
•
•
Join Date: Nov 2008
Posts: 5
Reputation:
Solved Threads: 0
C works in MFC right? (sprintf/sscanf)
c Syntax (Toggle Plain Text)
int main(int argc, char*argv[]) { int m,d,y; sscanf("%d/%d/%d", &m, &d, &y); if (checkdate(m,d,y)) { printf("valid\n"); } else { printf("invalid\n"); } } bool checkdate(int m, int d, int y) { //gregorian dates started in 1582 if (! (1582<= y ) )//comment these 2 lines out if it bothers you return false; if (! (1<= m && m<=12) ) return false; if (! (1<= d && d<=31) ) return false; if ( (d==31) && (m==2 || m==4 || m==6 || m==9 || m==11) ) return false; if ( (d==30) && (m==2) ) return false; if ( (m==2) && (d==29) && (y%4!=0) ) return false; if ( (m==2) && (d==29) && (y%400==0) ) return true; if ( (m==2) && (d==29) && (y%100==0) ) return false; if ( (m==2) && (d==29) && (y%4==0) ) return true; return true; }
Last edited by blacklight332; Mar 3rd, 2009 at 10:28 pm.
>Or did I miss the posting guidelines.
Yes you did. And it's appropriately titled "Read This Before Posting":
http://www.daniweb.com/forums/thread78223.html
Yes you did. And it's appropriately titled "Read This Before Posting":
http://www.daniweb.com/forums/thread78223.html
"Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
![]() |
Similar Threads
- Internet Explorer-OUT OF ORDER + More (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: Beginner and I would love help :) date validation
- Next Thread: Decimal to Binary Conversation stored into a char array
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game generator givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






