Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Field and Number Field

Status
Not open for further replies.

goslincm

MIS
May 23, 2006
292
US
I have a date field in the format 00/00/0000 and a number field that represents a year value. Is there a way to have my number field value add to the year only of my date field?
 
Sure. Save your mm/dd/yyyy field to a date datatype (datDate for now)
Then DATEADD ( datepart , number, date )

Or in this case DATEADD("year", YourNumberField, datDate)

If you are using Access(VBA) I think you have to use # delims on the string var:

Dim datDate as Date
datDate = "#mm/dd/yyyy#"

I have great faith in fools; self-confidence my friends call it.
-Poe
 
Alright, I have my [EffDate] in my table as a date type.
I also have my [ReviewDue] field saved as a date type, while the [Frequency] is a number field.

However, I've not used the DATEADD function before and cannot pull it all together to have the new values saved into the [ReviewDue] field.

 
You should not store computed values in a table. To generate a query showing the date the review is due
Code:
Select [EffDate]
     , [Frequency]
     , ... Other Fields ...
     , DateAdd("yyyy", [Frequency], [EffDate]) As [ReviewDue]

From myTable
If you must put them in the table
Code:
UPDATE myTable

SET ReviewDue = DateAdd("yyyy", [Frequency], [EffDate])
 
You wanted something like this (SQL code) ?
UPDATE yourTable
SET ReviewDue = DateAdd('yyyy', [Frequency], [EffDate])

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for the help. My question regarding using this in a query instead of a table is in querying for those reviews that are past due.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top