943,793 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 2214
  • C++ RSS
Nov 21st, 2008
0

C++ / MFC Date Validation

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
koushal.vv is offline Offline
35 posts
since Oct 2008
Nov 21st, 2008
0

Re: C++ / MFC Date Validation

you could try the parsedate() member of COleDateTime:
C++ Syntax (Toggle Plain Text)
  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 Nick Evan; Nov 21st, 2008 at 9:34 am.
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is online now Online
4,132 posts
since Oct 2006
Nov 22nd, 2008
0

Re: C++ / MFC Date Validation

Thanks
Reputation Points: 10
Solved Threads: 1
Light Poster
koushal.vv is offline Offline
35 posts
since Oct 2008
Mar 3rd, 2009
0

Re: C++ / MFC Date Validation

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.
Reputation Points: 21
Solved Threads: 0
Newbie Poster
blacklight332 is offline Offline
5 posts
since Nov 2008
Mar 3rd, 2009
0

Re: C++ / MFC Date Validation

Stop spamming old threads, you *******!
Last edited by MosaicFuneral; Mar 3rd, 2009 at 10:18 pm.
Reputation Points: 888
Solved Threads: 114
Nearly a Posting Virtuoso
MosaicFuneral is offline Offline
1,270 posts
since Nov 2008
Mar 3rd, 2009
0

Re: C++ / MFC Date Validation

@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.
Reputation Points: 21
Solved Threads: 0
Newbie Poster
blacklight332 is offline Offline
5 posts
since Nov 2008
Mar 3rd, 2009
1

Re: C++ / MFC Date Validation

>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
Team Colleague
Reputation Points: 2240
Solved Threads: 338
Vampirical Lurker
John A is offline Offline
5,055 posts
since Apr 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: unable to add char array of numbers to another char array
Next Thread in C++ Forum Timeline: Decimal to Binary Conversation stored into a char array





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC