C++ / MFC Date Validation

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2008
Posts: 35
Reputation: koushal.vv is an unknown quantity at this point 
Solved Threads: 1
koushal.vv koushal.vv is offline Offline
Light Poster

C++ / MFC Date Validation

 
0
  #1
Nov 21st, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,832
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 297
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is online now Online
Roasting Maven

Re: C++ / MFC Date Validation

 
0
  #2
Nov 21st, 2008
you could try the parsedate() member of COleDateTime:
  1. if (!COleDateTime::ParseDateTime("12/11/2008")
  2. {
  3. // That's not a date bucko!
  4. }

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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 35
Reputation: koushal.vv is an unknown quantity at this point 
Solved Threads: 1
koushal.vv koushal.vv is offline Offline
Light Poster

Re: C++ / MFC Date Validation

 
0
  #3
Nov 22nd, 2008
Thanks
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 5
Reputation: blacklight332 is an unknown quantity at this point 
Solved Threads: 0
blacklight332 blacklight332 is offline Offline
Newbie Poster

Re: C++ / MFC Date Validation

 
0
  #4
Mar 3rd, 2009
C works in MFC right? (sprintf/sscanf)
  1. int main(int argc, char*argv[])
  2. {
  3. int m,d,y;
  4. sscanf("%d/%d/%d", &m, &d, &y);
  5. if (checkdate(m,d,y))
  6. {
  7. printf("valid\n");
  8. }
  9. else
  10. {
  11. printf("invalid\n");
  12. }
  13. }
  14.  
  15.  
  16. bool checkdate(int m, int d, int y)
  17. {
  18. //gregorian dates started in 1582
  19. if (! (1582<= y ) )//comment these 2 lines out if it bothers you
  20. return false;
  21. if (! (1<= m && m<=12) )
  22. return false;
  23. if (! (1<= d && d<=31) )
  24. return false;
  25. if ( (d==31) && (m==2 || m==4 || m==6 || m==9 || m==11) )
  26. return false;
  27. if ( (d==30) && (m==2) )
  28. return false;
  29. if ( (m==2) && (d==29) && (y%4!=0) )
  30. return false;
  31. if ( (m==2) && (d==29) && (y%400==0) )
  32. return true;
  33. if ( (m==2) && (d==29) && (y%100==0) )
  34. return false;
  35. if ( (m==2) && (d==29) && (y%4==0) )
  36. return true;
  37.  
  38. return true;
  39. }
Last edited by blacklight332; Mar 3rd, 2009 at 10:28 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 949
Reputation: MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice 
Solved Threads: 92
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is offline Offline
Posting Shark

Re: C++ / MFC Date Validation

 
0
  #5
Mar 3rd, 2009
Stop spamming old threads, you *******!
Last edited by MosaicFuneral; Mar 3rd, 2009 at 10:18 pm.
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 5
Reputation: blacklight332 is an unknown quantity at this point 
Solved Threads: 0
blacklight332 blacklight332 is offline Offline
Newbie Poster

Re: C++ / MFC Date Validation

 
0
  #6
Mar 3rd, 2009
@MosaicFuneral

What are you talking about? Isn't this a CODE FORUM. So posting CODE on a CODE FORUM is okay right? Or did I miss the posting guidelines.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: C++ / MFC Date Validation

 
0
  #7
Mar 3rd, 2009
>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
"Technological progress is like an axe in the hands of a pathological criminal."
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC