RSS Forums RSS

C++ / MFC Date Validation

Please support our C++ advertiser: Programming Forums
Thread Solved
Reply
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

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Posts: 2,353
Reputation: niek_e has much to be proud of niek_e has much to be proud of niek_e has much to be proud of niek_e has much to be proud of niek_e has much to be proud of niek_e has much to be proud of niek_e has much to be proud of niek_e has much to be proud of niek_e has much to be proud of niek_e has much to be proud of 
Solved Threads: 256
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Nearly a Posting Maven

Re: C++ / MFC Date Validation

  #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 8:34 am.
Want better/more replies to your questions? Wrap your code in [code] [/code] tags!
Reply With Quote  
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

  #3  
Nov 22nd, 2008
Thanks
Reply With Quote  
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

  #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 9:28 pm.
Reply With Quote  
Posts: 717
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: 80
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is offline Offline
Master Poster

Re: C++ / MFC Date Validation

  #5  
Mar 3rd, 2009
Stop spamming old threads, you *******!
Last edited by MosaicFuneral : Mar 3rd, 2009 at 9: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  
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

  #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  
Posts: 4,810
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 
Solved Threads: 324
Moderator
Featured Blogger
John A's Avatar
John A John A is offline Offline
Vampirical Moderator

Re: C++ / MFC Date Validation

  #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
Come join the official DaniWeb IRC community chat
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the C++ Forum
Views: 820 | Replies: 6 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:36 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC