• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Write a bulletproof date validation routine. Meg Senior Member Posts: 480 Threads: 24 Joined: Mar 2003 10-17-2004, 08:49 PM These are formulas I came up with. I'll try to explain them. ok when you test an equation, QB returns 0 (false) or -1 (true). even numbered months before august (month#8) and odd numbered months after July (month#7) have 30 days (except feb, but that's covered in line 2) So, line 1 is an equation that starts with 31 days and adds the validity of the above statement. If it's true, it subtracts 1, leaving 30 days. Code:`DInM% = 31 + (m% MOD 2) * (m% > 7) + (m% MOD 2 XOR 1) * (m% < 8)` I'll break it apart: Code:```31                      default value m% MOD 2                returns 0 if date is even, 1 if date is odd m% > 7                  returns -1 if date is > 7, 0 if date < 8 m% MOD 2 XOR 1          returns 0 if date is odd, 1 if date is even m% < 8                  returns -1 if date is < 8, 0 if date > 7``` now, we multiply the first two and the second two together: Code:```(m% MOD 2) * (m% > 7)                returns -1 if date is odd and > 7 (m% MOD 2 XOR 1) * (m% < 8)          returns -1 if date is even and < 8``` so if either one of these is true, 31 gets added to -1 and 0 for a result of 30 otherwise, 31 gets added to 0 and 0 for a result of 31 since both products can't be -1, you never end up with 31+ -1 + -1 = 29. Code:`IF m% = 2 THEN DInM% = 28 - ((y% MOD 4 = 0) + (y% MOD 100 = 0) * NOT (y% MOD 400 = 0))` This line does pretty much the same thing, only it starts with 28 as the default value and adds 1 if: 1. the year is evenly divisible by 4, unless the year is evenly divisible by 100 and not evenly divisible by 400. Code:```28                      default value y% MOD 4 = 0            returns -1 if year is divisible by 4, otherwise 0 y% MOD 100 = 0          returns -1 if year is divisible by 100, otherwise 0 y% MOD 400 = 0          returns -1 if year is divisible by 400, otherwise 0``` I hope this clears it up! *peace* Meg. edit: another alternative to line #1 is: Code:`DinM% = VAL(MID\$("312831303130313130313031", m% * 2 - 1, 2))` so using your bit of code (which i like!) it would be this: Code:```DinM% = VAL(MID\$("312831303130313130313031", m% * 2 - 1, 2)) IF DinM% = 2 then DinM% = 28 - ((m% MOD 4 = 0 AND m% MOD 100 <> 0) OR (m% MOD 400 = 0))``` « Next Oldest | Next Newest »

 Messages In This Thread Write a bulletproof date validation routine. - by Moneo - 10-11-2004, 06:00 AM My entry - by Meg - 10-11-2004, 09:03 PM Write a bulletproof date validation routine. - by Z!re - 10-12-2004, 12:40 AM Write a bulletproof date validation routine. - by Meg - 10-12-2004, 01:09 AM Write a bulletproof date validation routine. - by Antoni Gual - 10-12-2004, 04:11 AM Write a bulletproof date validation routine. - by Moneo - 10-12-2004, 08:21 AM Write a bulletproof date validation routine. - by Z!re - 10-12-2004, 02:52 PM updated - by Meg - 10-12-2004, 08:01 PM Write a bulletproof date validation routine. - by Moneo - 10-15-2004, 07:53 AM Write a bulletproof date validation routine. - by Moneo - 10-17-2004, 06:55 AM Write a bulletproof date validation routine. - by Meg - 10-17-2004, 08:49 PM Write a bulletproof date validation routine. - by Moneo - 10-18-2004, 05:16 AM Write a bulletproof date validation routine. - by Meg - 10-18-2004, 10:13 AM Some thoughts from the real world experience... - by ToohTooh - 10-23-2004, 12:18 AM /nod - by Meg - 10-23-2004, 01:34 AM Re: Some thoughts from the real world experience... - by oracle - 10-23-2004, 08:06 AM Re: Some thoughts from the real world experience... - by Moneo - 10-24-2004, 06:38 AM Write a bulletproof date validation routine. - by Neo - 10-24-2004, 03:22 PM Clarification of suggestion numbered (4), and an example. - by ToohTooh - 10-25-2004, 01:15 PM Re: Clarification of suggestion numbered (4), and an example - by oracle - 10-26-2004, 04:35 AM Write a bulletproof date validation routine. - by Moneo - 10-26-2004, 07:03 AM Re: Clarification of suggestion numbered (4), and an example - by Moneo - 10-26-2004, 07:10 AM Write a bulletproof date validation routine. - by Neo - 10-26-2004, 02:59 PM Foo - by ToohTooh - 10-26-2004, 10:36 PM Reply on Clarification Suggestion - by Neo - 10-26-2004, 11:37 PM Re: Reply on Clarification Suggestion - by oracle - 10-27-2004, 02:00 AM Hmm... - by ToohTooh - 10-27-2004, 02:12 PM Write a bulletproof date validation routine. - by Meg - 10-27-2004, 07:11 PM Re: Hmm... - by Neo - 10-27-2004, 10:12 PM Write a bulletproof date validation routine. - by oracle - 10-28-2004, 02:38 AM Write a bulletproof date validation routine. - by Neo - 10-29-2004, 02:28 PM Write a bulletproof date validation routine. - by Moneo - 10-30-2004, 11:13 PM Write a bulletproof date validation routine. - by Neo - 11-01-2004, 01:21 AM Write a bulletproof date validation routine. - by Moneo - 11-01-2004, 04:29 AM Write a bulletproof date validation routine. - by Z!re - 11-01-2004, 04:43 AM Write a bulletproof date validation routine. - by Neo - 11-01-2004, 12:13 PM Write a bulletproof date validation routine. - by Neo - 11-01-2004, 04:14 PM Thank you. - by ToohTooh - 11-01-2004, 04:54 PM Write a bulletproof date validation routine. - by Neo - 11-01-2004, 04:57 PM Write a bulletproof date validation routine. - by dark ninja - 11-20-2004, 06:10 AM Write a bulletproof date validation routine. - by Neo - 11-20-2004, 05:50 PM Write a bulletproof date validation routine. - by dark ninja - 11-20-2004, 06:29 PM Write a bulletproof date validation routine. - by Neo - 11-20-2004, 09:30 PM Write a bulletproof date validation routine. - by Moneo - 11-21-2004, 07:23 AM Write a bulletproof date validation routine. - by Neo - 11-21-2004, 05:12 PM Write a bulletproof date validation routine. - by Moneo - 07-25-2006, 07:28 AM Write a bulletproof date validation routine. - by Neo - 07-26-2006, 04:06 PM Write a bulletproof date validation routine. - by yetifoot - 07-27-2006, 08:17 AM Write a bulletproof date validation routine. - by Moneo - 07-27-2006, 09:51 AM Write a bulletproof date validation routine. - by Moneo - 07-27-2006, 09:53 AM Write a bulletproof date validation routine. - by yetifoot - 07-27-2006, 10:52 AM Write a bulletproof date validation routine. - by Moneo - 07-28-2006, 08:07 AM Write a bulletproof date validation routine. - by yetifoot - 07-28-2006, 11:52 PM Write a bulletproof date validation routine. - by Moneo - 07-29-2006, 04:11 AM

Forum Jump:

Users browsing this thread: 1 Guest(s)