473,386 Members | 1,699 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,386 software developers and data experts.

about searching Dates within a range using quries or SQL

Hi! all

this is probably been answered in part elsewhere but does anyone know how to get Dates that are 30 days from the current date on the system?

my Database has a field to hold the Warranty End Date for a computer system.

the user can either Enter "N/A" or a Date in this format dd/mm/yy anything else and it should popup a msgbox indicating a problem.

to allow the use of N/A and the "/" in the Date i set it to text field and even when i use the DateValue and DateDiff functions to try and convert the Date from text to a number and then compare to now using Datediff i get all sorts of different errors including Data type mismatch

i've played around with DatePart and some other functions i found as well..to no avail.

so if a field has a date in it and not "N/A" then it needs to search which are 30 days from expiry.

i know i'll have to construct a seperate search to filter all the "N/A"s out of the records being passed to this particular search but just wondering how to do this bit and whether i can do both in one search or patch of SQL..

Thanks!
Aug 3 '07 #1
7 1661
Rabbit
12,516 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. ExpDate: iif(DateField = "N/A", "", CDate(DateField))
  2. Criteria = BETWEEN Date() AND DateAdd("d", 30, Date())
  3.  
Aug 3 '07 #2
Expand|Select|Wrap|Line Numbers
  1. ExpDate: iif(DateField = "N/A", "", CDate(DateField))
  2. Criteria = BETWEEN Date() AND DateAdd("d", 30, Date())
  3.  

thanks for that Rabbit!

i'll chuck that in and give it a try..

BTW: iif ?? is that meant to have 2 i's? or that a typo?
Aug 6 '07 #3
Rabbit
12,516 Expert Mod 8TB
iif is meant to have two i's, it's supposed to mean "if and only if".
Aug 6 '07 #4
oops! forgot to ask..Rabbit umm does the text in line 1 for the data validation rule (like how only NA or a date can be entered) or is it part of the text i should chuck into my Warrenty End Date query??

sorry i know i said i'd chuck it in and see if it works..but i only got a chance to access the school's Dbase just today and i've been flat out prepping for Uni Exams..so i forgot where i was meant to place it..
Aug 8 '07 #5
Rabbit
12,516 Expert Mod 8TB
The two lines are what you would put in the query. The second line is the criteria for the calculated field.
Aug 8 '07 #6
Sorry to be such a pain in the bum Rabbit..

but i did as you said and even when i puposely modified a comp to expire on the 1/9/07

the query didnt show anything

here's the code in SQL format since i cant screendump from the school's comp for some reason.. man i really should have gone back and re-do all my access course this is making me feel so stupid right now..~_~

Expand|Select|Wrap|Line Numbers
  1. SELECT ComputerDatabase.[Primary ID], ComputerDatabase.[Computer Name], ComputerDatabase.[Asset number], ComputerDatabase.[Serial number], ComputerDatabase.[Computer Model], ComputerDatabase.[Port number], ComputerDatabase.Location, ComputerDatabase.[Warranty End Date], ComputerDatabase.[Computer Usage type], ComputerDatabase.[Misc info]
  2. FROM ComputerDatabase
  3. WHERE (((IIf([Warranty End Date]="N/A","",CDate([Warranty End Date]))) Between Date() And DateAdd("d",30,Date())));
  4.  
BTW: the query gave me an "invalid use of Null" error until i when thru the dbase and manually filled in every comp that didnt have a warranty end date with "N/A". after that it ran..but doesnt show anything.. >_<
Aug 10 '07 #7
Rabbit
12,516 Expert Mod 8TB
Try putting the CDate around the iif statement instead.
Aug 10 '07 #8

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

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
8
by: netsurfer | last post by:
Hi: Have a question on making the date automatically filled in by what the user enters in by the date at the top. The date entered at the top would most likely be on a Wednesday then I need...
7
by: smcgouga | last post by:
Visual Basic 6. ADO 2.8 I have an as400 DB2 V5R1 datasource. Dates are defined as *ISO format and have a range from '0001-01-01' to '9999-12-31'. I am trying to update a date field on the...
1
by: Saso Zagoranski | last post by:
Hi! This is not exactly a C# question but I don't know where else to post it... I'm making an application where the user keeps track of it's art collection... I'm also trying to implement a...
3
by: Nathan | last post by:
Hi, I can't seem to this part of my function to work: Private Function TotalHours(ByVal InTime As Date, ByVal OutTime As Date) As Double Msgbox(InTime.Tostring) Select Case InTime Case...
2
by: Carl | last post by:
Hi, I have a query that produces an output similar to the sample shown below. These records are based on certain criteria and a date range selected from a form. I need to create some kind of...
3
by: rugger81 | last post by:
I am currently working in the sql server 2000 environment and I want to write a function to pull all dates within a given date range. I have created several diferent ways to do this but I am...
7
by: evilcowstare via AccessMonster.com | last post by:
Hi, I have searched the forum for answers on this and to be honest as a novice I find it a bit confusing so apologies if it is simple. There are some searches that I want to apply to my database....
3
by: rengaraj | last post by:
hi frens I want to know some information/ explaination from SQL.. I want to know about join queries, subquries, timestamps, date_part, date_trunc, case and cast data type.. Do anyone...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.