473,399 Members | 3,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Detecting an Invalid Date

133 100+
When a date field contains an invalid date, it needs to be flagged. However, my code is not acknowledging it. For instance, it doesn't recognize 8/15/0007 as a bad date. Any assistance would be appreciated.


Expand|Select|Wrap|Line Numbers
  1.             If IsDate(rst_AllText_PRData_Editable_Dates![Contract Effective Date]) = False Then
  2.                 rst_tbl_PRData_Error_Dates.Add
  3.                     rst_tbl_PRData_Error_Dates.[Contract Effective Date] = rst_AllText_PRData_Editable_Dates![Contract Effective Date]
  4.                 rst_tbl_PRData_Error_Dates.Update
  5.             End If
  6.  
Oct 19 '15 #1

✓ answered by hvsummer

I think you should trap your condition Year(field) between startYear and EndYear for your problem
ex:
Expand|Select|Wrap|Line Numbers
  1. If IsDate(rst_AllText_PRData_Editable_Dates![Contract Effective Date]) = False and year(rst_AllText_PRData_Editable_Dates![Contract Effective Date]) not between 1900 and 3000 Then
  2.                 rst_tbl_PRData_Error_Dates.Add
  3.                     rst_tbl_PRData_Error_Dates.[Contract Effective Date] = rst_AllText_PRData_Editable_Dates![Contract Effective Date]
  4.                 rst_tbl_PRData_Error_Dates.Update
  5. End If
  6.  

11 3423
Rabbit
12,516 Expert Mod 8TB
Why isn't it a valid date? There is such a thing as year 0007.
Oct 19 '15 #2
NeoPa
32,556 Expert Mod 16PB
If you want to use the term 'invalid date' differently from how most people would understand it then you should define what you mean clearly in your question. That way we can respond intelligently to it.
Oct 20 '15 #3
hvsummer
215 128KB
I think you should trap your condition Year(field) between startYear and EndYear for your problem
ex:
Expand|Select|Wrap|Line Numbers
  1. If IsDate(rst_AllText_PRData_Editable_Dates![Contract Effective Date]) = False and year(rst_AllText_PRData_Editable_Dates![Contract Effective Date]) not between 1900 and 3000 Then
  2.                 rst_tbl_PRData_Error_Dates.Add
  3.                     rst_tbl_PRData_Error_Dates.[Contract Effective Date] = rst_AllText_PRData_Editable_Dates![Contract Effective Date]
  4.                 rst_tbl_PRData_Error_Dates.Update
  5. End If
  6.  
Oct 20 '15 #4
dowlingm815
133 100+
There is an issue with the syntax for year. Can you pls guide? The pound sign is flagged.

Expand|Select|Wrap|Line Numbers
  1. If IsDate(DateValue(rst_AllText_PRData_Editable_Dates![Contract Effective Date])) = False _
  2.                     and year(rst_AllText_PRData_Editable_Dates![Contract Effective Date]) Between #2009# and #2025# Then
When the
Expand|Select|Wrap|Line Numbers
  1. #" &2009& "#
syntax is used, it flags it as well.
Oct 20 '15 #5
hvsummer
215 128KB
you don't have to put # # around the year value inside between .. and .., since year() function return numberic datatype.

Edit: using NOT + Between ... AND ...
you miss the NOT, then condition combine will be wrong in ur current code.
this Code need NOT + Between:
Expand|Select|Wrap|Line Numbers
  1. If IsDate(DateValue(rst_AllText_PRData_Editable_Dates![Contract Effective Date])) = False _
  2.                     and year(rst_AllText_PRData_Editable_Dates![Contract Effective Date]) Between #2009# and #2025# Then
  3.  
Oct 20 '15 #6
dowlingm815
133 100+
Thank you, however, the vba is still flagging an syntax error on the code.


Expand|Select|Wrap|Line Numbers
  1.  If IsDate(DateValue(rst_AllText_PRData_Editable_Dates![Contract Effective Date])) = False _
  2.                         and year(rst_AllText_PRData_Editable_Dates![Contract Effective Date]) NOT Between 2009 And 2025 Then
  3.     End If
Oct 20 '15 #7
hvsummer
215 128KB
ok, I know where is the problem.

just replace "NOT between ... and.." syntax with

Expand|Select|Wrap|Line Numbers
  1. year(rst_AllText_PRData_Editable_Dates![Contract Effective Date]) < 2009 or year(rst_AllText_PRData_Editable_Dates![Contract Effective Date]) > 2025 Then
  2.  
Oct 21 '15 #8
NeoPa
32,556 Expert Mod 16PB
This is getting silly. You haven't explained what you consider to be invalid in a date value for the question, and now you haven't given the VBA error message but ask for help with VBA syntax error.

I would have thought the necessity of providing the basic information in a question would be obvious to everyone. Please do so before proceeding in order to avoid this thread going further into territory that no-one can understand.

Frankly, I have no idea why anyone is suggesting answers before the question is clear. Clearly there is no 'Best Answer' at this stage as we haven't even got to a properly expressed question.
Oct 21 '15 #9
hvsummer
215 128KB
@NeoPa: I think I know what he's facing, sorry that I did not explain.

the fact that data type or date/time setting in windows is not correct leading to that year of date field can be like this

1/1/40001 or 8/15/0007
(office still understand this as valid year (decode into 1900 or 2000 whatever)

but we can't work with it (import this can lead to wrong year number, or manually typing may lead thing by far going worse)

he need to set condition for his date field that force to contain year only between valid range

to do this he used his code to flag/note/remind in an addition field (1 is yes, 0 is no for example) to show that rows is wrong date (wrong year format).

so I suggest him to set additional condition for year of his field by year() function trapped in valid range ("Not between and" -OR- "< 1900 or > 2025")
Oct 21 '15 #10
dowlingm815
133 100+
@hvsummer, thanks for explaining. Mary
Oct 21 '15 #11
NeoPa
32,556 Expert Mod 16PB
Right. That starts to make some sense.

@HVSummer.
No need to apologise. It's not your responsibility to ask the question clearly, or even to explain it when you understand what it is. Well done anyway for doing so.

In light of the explanation, and the fact that an explanation of what the question should have been is never appropriate for a 'Best Answer' post, I will reset it again, but set your earlier post back up as 'Best Answer' instead. That is an answer to the question and also explains the process behind the code.

@Mary.
I do understand that expressing questions clearly and fully enough is difficult for most people. The number of poorly expressed questions in here makes it impossible for me not to realise that it's a very common problem. Nevertheless, please do your best when posting questions. Often experts will prompt you for extra information. It's very important that you reply to these with the information in order to get the question understood by as many as possible.
Oct 21 '15 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: GaudaPrime | last post by:
Hi, I have an Oracle 8i instance which has somehow managed to store the 29th of February 2005 in a date field. As 2005 isn't a leap year this is an invalid date. SQL> select NEXTTRIG_DATE,...
0
by: Mike D | last post by:
now and again i've noticed that the Received field in a table linked from an Exchange server will have an invalid date. the invalid date always seems to be some day and some month in the year...
7
by: simonmarkjones | last post by:
Hi, I have a report i would like created based upon a date the user types in. I have a query which in the criteria section of my date field i have put . The report is created fine when a...
1
by: Hadi | last post by:
Hello, I have to DateTime structure, how do I calculate if date A is on the same week with date B or last week of date B? Thanks, Hadi
3
by: Mage | last post by:
Hi, can pgsql acceppt invalid date values? Sometimes it would be nice to convert 2003-02-29 to 2003-03-01 or to 2003-02-28 automatically instead of throwing back an error message. Mage ...
2
by: gavin | last post by:
Have a Windows for with a textbox. Enter a date 2006/1/1/ -Note an additinal / on th end This is clearly an error but when text is cast to a date the extra / is automatically removed. The cast...
2
by: kannan1983 | last post by:
Iam having a column which contains year (e.g 2005,2006), i have to validate each and every value in this column, if it is like(e.g.20005,20600,200060006) i have to caputure this value , for that i...
2
by: Andrew Poulos | last post by:
If I check for a invalid date e.g. February 30th, 2008? Andrew Poulos
3
by: E11esar | last post by:
Hi there. I am trying to pass a date from a TextBox in my asp.net (c#) web page when invoking an insert button. The date in question is of the type DD/MM/YYYY and has a value of "14/09/2007"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.