DateAdd + Days
Jun 19, 2006
I have a table that has several fields however the ones I'm working with are Date, Letter, RollOff.
Date being the date the record was entered example 6/1/2006
Letter can be letter codes simply a,b,c,d,e etc
RollOff is 1 year from the Date the record was entered.
I've searched though several pages of dateadd info but haven't ran across an exact similar situation so far.
Getting the RollOff is no problem, simply DateAdd("yyyy",1, [Date]). However what I'm attempting to do is I need to add a certain amount of days to the calc between the date entered and the 1 year rolloff that match the Letter of "B".
Each record entered will only have 1 Letter and each entry is only for 1 day.
I'm thinking I will need a second query that will gather the sum of "B" codes to determine the amount of days needed to add to my DateAdd calc.
sample layout would be.
Date Letter RollOff
6/1/2006 A DateAdd("yyyy", 1, [Date]) + 3 days of B Codes for 6/2,3,4
6/2/2006 B
6/3/2006 B
6/4/2006 B
6/5/2006 C
Since 6/1/2006 RollOff is 1 year 6/1/2007 however since there was "B" enteries between the time the record was entered and the RollOff date the amount of days needed to be added so the RollOff would actually be 6/4/2007.
Any help would be appreciated.
View Replies
ADVERTISEMENT
Sep 11, 2014
I have a form called subfrm_vactions
rowsource is a query called qryVacations
the query should calculated two things
1 - the difference between start_vac and End_vac in days to calculate the vacation period and put the value in field called Period (working well)
2-the work days which the period between the last day in Previous record (End_Vac) and the (Start_Vac) in the next record (didn't work)
the result is the difference between (End_Vac) and (Start_Vac) in the same record which i don't want
simply i want to calculate the work days.
View 5 Replies
View Related
Jan 24, 2014
I have to count the number of days each week (7 days) that a person has worked - simple enough.
But - what if they come off the job within the week?
I have been using the DateDiff function which is fine.
In the database they have a Mobdate and a DeMobDate but if the DeMobDate falls within the week the whole thing falls apart?
View 2 Replies
View Related
Dec 14, 2004
Hello everyone,
I have problem with my code here. I am using this code to determine if the LogDate with a weekday of Sunday can be declare as Sunday Work or Regular Work. The 1st week of my entry can determine if the LogDate is Sunday then compute if it reaches a 7 days working, if he is absent even 1 (one) day in his previous working days within the week. His Sunday LogDate is considered as Regular Days instead of Sunday Work. Can anyone tell me what is wrong in this code?
The problem here is the computation of 7 days after 1 week. There should be a 7 days computation every week per month in able to declare Sunday Work or Regular Work. I tried this code but it did not work on 2nd week, 3rd week and 4th week of the month.
How come on 2nd week, Sunday (LogDate) is not considered as Sunday Work even he completed the 7 days (working days) per week? I need help on this ASAP Thanks
Tim
Below is the code i'm using for defining Regular days and Sunday Working Days:
Private Sub LogDate_AfterUpdate()
Dim rst As DAO.Recordset, rs As DAO.Recordset
Dim db As DAO.Database
Dim dteToday As Date, dtePrior As Date
Dim i As Integer
dteToday = LogDate
dtePrior = DateAdd("d", -6, dteToday)
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT [HolidayDate] FROM tblHolidays", dbOpenSnapshot)
rst.FindFirst "[HolidayDate] = #" & dteToday & "#"
'See if the date entered is a holiday
If rst.NoMatch Then
Holiday.Value = 0
Else
Holiday.Value = 1
End If
If Weekday(dteToday) = vbSunday Then 'If dated entered is a Sunday determine if
Dim strSQL As String 'it will be a regular day or a Sunday
strSQL = "SELECT [LogDate] "
strSQL = strSQL & "FROM tblLog "
strSQL = strSQL & "WHERE [LogDate] >= #" & dtePrior & "#"
strSQL = strSQL & " AND [LogDate] <= #" & dteToday & "#"
'Create a recordset of records from date entered and 7 days prior
Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)
rs.MoveLast
i = rs.RecordCount 'Count the number of days between the two dates
If i = 7 Then 'If there are seven days then it is a Sunday
Sunday.Value = 1
Else
Sunday.Value = 0 'If less than 7 days then it is a regular day
End If
Else
Sunday.Value = 0
End If
DayofWeek.Value = Format(dteToday, "dddd")
End Sub
View 1 Replies
View Related
Jun 14, 2013
Is there a way i can convert the weekend days into working days for example.
5/4/13 1:30 PM is on saturday what function can I use to make this day read 5/6/13 8:00 Am which is monday. Same thing for holidays.
View 1 Replies
View Related
Apr 14, 2014
I have a form where a start date is inputted (Inputfrm , StartDate) and a form where the end date of the process is recorded (Inspectionfrm , EndDate) and these both record in the table InputTbl as StartDate and EndDate respectively.
I have created a union query which shows a list of all the dates where there is work recorded (WorkingDatesQry and the column of list of unique dates is "WorkingDate"), and as we run a highly varied schedule depending on time of the year and order numbers I cannot just use a query which says Monday-Friday or Tuesday - Saturday.What I am trying to do is to find the number of days between StartDate and EndDate where there is a date recorded in the WorkingDates query.
View 1 Replies
View Related
Apr 3, 2013
Client has asked me to create a report showing summary of monthly sales by day. That was easy. I created a query for the month the user selected and then summarized and group the data by day. Client like the result but would like to see zeros on the report for non sales days. Non sales days are days like holidays and there are no sales.
I am thinking of creating an table with 31 days of zero values and then join the two tables in a query? Or, should I create a temporary table with code and then merge the two tables which the existing query which I can then use for the report?
View 4 Replies
View Related
Dec 4, 2006
I have a query and I need the records to display 3 working days before the 15 working day deadline.
I used the following in the criteria box below the received date field and it doesn't pull the correct number of workdays, it's pulling calendar days instead.
<=DateAdd("w",-12,Date())
Can anyone help, thanks for your time!!!
View 8 Replies
View Related
Dec 4, 2006
I have a query and I need the records to display 3 working days before the 15 working day deadline.
I used the following in the criteria box below the received date field and it doesn't pull the correct number of workdays, it's pulling calendar days instead.
<=DateAdd("w",-12,Date())
Can anyone help, thanks for your time!!!
View 6 Replies
View Related
Dec 26, 2006
I rent out a property , on the rental statement I have a field [Datepaid], [RentpaidFrom] and [rentpaidTo]. I would to have a field that can calculate the rent that is paid to show if the rent is in arrears or in Advance. I guess the code would be something like (datediff ???? etc) but i have no idea what it should be. the calculation should appear on the query as i.e.2 days in arrears or 12 days in advance etc
your help would be much appreciated
merry christmas to you all
Jabez
View 4 Replies
View Related
Mar 14, 2006
Dear All,
I'm new to VBA coding. A code below is copied from a friend of mine and I can't make it work. How to call up this function in my form. In my form I have 3 text boxes (StartDate, EndDate and NumOfWorkDays). My form is based on a table.
Please anyone who would help me on this, kindly give me the step by step procedure as I am really novice. Thanks in advance.
'*********** Code Start **************
Public Function WorkingDays(StartDate As Date, EndDate As Date) As Integer
On Error GoTo Err_WorkingDays
Dim intCount As Integer
StartDate = StartDate + 1
'If you want to count the day of StartDate as the 1st day
'Comment out the line above
intCount = 0
Do While StartDate <= EndDate
'Make the above < and not <= to not count the EndDate
Select Case WeekDay(StartDate)
Case Is = 1, 7
intCount = intCount
Case Is = 2, 3, 4, 5, 6
intCount = intCount + 1
End Select
StartDate = StartDate + 1
Loop
WorkingDays = intCount
Exit_WorkingDays:
Exit Function
Err_WorkingDays:
Select Case Err
Case Else
MsgBox Err.Description
Resume Exit_WorkingDays
End Select
End Function
'xxxxxxxxxxxxxxxxxxxxxxxx
Can someone please direct me to the right path.
Your help is highly appreciated.
qwerty70
View 1 Replies
View Related
Sep 14, 2007
I have a table that includes a client account number, revenue, and a Date in the format YYYYMM. I would like to create a query that sums the revenue for a client where the date is six months prior to today.
Thanks in advance
View 2 Replies
View Related
Oct 13, 2004
I think I have a simple problem: In a database table I've made there is a field called <date> (in the date&time format), in the table there is another date field, which should contain a date always 6 months later than the <date> field. For conveniance, I created a form to fill in all other fields in the table, including the <date> field. Succesfully I tried to calculate the 6-months-ahead-date in the form with DateAdd, but I tried everything I could (which is not so much) to store this result in the table, since I need it there for a few reports I generate.
Who can help me to solve this problem??
View 2 Replies
View Related
Feb 18, 2007
Hi,
This problem has to be easy but I can't make it work. The attached database has a table name BOL information. Inside that table are the two columns I'm having an issue with. I want ETA Date to be 30 days after BOL date. I have been screwing around with the Dateadd function and can't get it to work. I have been putting the following in the default value of ETA date:
Dateadd("d",30,[BOL Date])
The error message I have been getting is The database engine does not recognize either the field 'BOL Date' in a validation expression, or the default value in the table 'BOL information'.
What am I doing wrong? Should I not be putting the formula in the default value? Should I use another way to get this calculation? Your thoughts are most welcome.
Thanks in advance.
Eddie.
View 2 Replies
View Related
Jan 3, 2008
I have a table that tracks the inspection dates for various structures. I have a field called InspectionDate in the form of 99/99/9999. Another field called Interval which can range from 6 months to 48 months. I have always gone in to edit another field called InspectionDueDate. Is there a way to have the InspectionDueDate field automatically be filled based on the other 2 fields? Does this make any sense? Thanks in advance.
View 4 Replies
View Related
Jun 28, 2005
Howdy all,
I've written a simple little function using the DateAdd system function which i call from query. Here's the logic
If (PassFail = "Pass") Then
IsNull (FirstRepairDueDate)
Else
FirstRepairDueDate = DateAdd("d", 5, InspectionDate)
End If
basically if the PassFail argument is "Pass" I would like the function to not display anything, however i'm not sure what to do because my function returns a data type of Date, which it defaults to 12:00:00 AM using the above logic.
Any ideas?
Many thanks
View 5 Replies
View Related
Oct 23, 2005
I'm VERY new at using VBA although I have been programming for many years.
I have a requirement that involves creating a new version of a record and setting the expiry date of the current version to one day less than the effective date of the new version.
Regardless of what I try, the new expiry date that gets set is always 12/30/1899.
I suspect there is something very elementary that I'm missing, but haven't been able to figure out what it might be. Perhaps I need to apply a function to the setExpiryDate variable?
Any suggestions would be appreciated. Here is the current version of the code I'm working with:
Private Sub createNewVersion_Click()
Dim strUpdate As String
Dim intervalType As String
Dim adjustment As Integer
Dim setExpiryDate As Date
Dim newEffDate As Date
intervalType = "d"
adjustment = -1
newEffDate = Forms!fCreateDomainVersion!NewEffectiveDate
setExpiryDate = DateAdd("d", -1, newEffDate)
strUpdate = "UPDATE tDomain " & _
"SET ExpiryDate = " & setExpiryDate & _
" WHERE DomainName = Forms!fCreateDomainVersion!DomainName AND " & _
"EffectiveDate = Forms!fCreateDomainVersion!EffectiveDate;"
DoCmd.RunSQL strUpdate
End Sub
View 1 Replies
View Related
Nov 27, 2005
Hello
I'm very new at this - just found out about the DateAdd function today trying to solve my problem, so that you know who you're dealing with.
Let's say Im operating a video rental shop, and want to calculate a DateDue (=when videos need to be returned) based on DateRented and number of videos rented..
DateAdd ("d", 5, [DateRented]) would be appropriate for 5 videos rented at once.
I want to replace 5 here with a number of videos rented, and this number (TAPECOUNT below) is also calculated in a query using count function (to count the number of videos associated with each rental)
Preferably I would end up with a single query consisting of 4 columns:
RENTAL_ID, TAPECOUNT, DATERENTED, DATEDUE, of which both 2nd and 4th column would be calculated, 2nd in combination with 3rd serving as input for 4th.
Can it be done like this and how? Would I need to store TAPECOUNT value first? Is DateAdd even a proper function for my task? I'm open to all suggestions, just keep in mind I'm a newbie.
View 4 Replies
View Related
Jan 13, 2007
I have table with two fields, [StartTime] and [FinishingTime].
On an unbound form (frmGameBooking), the [StartTime] is entered and also (via a combo box) the number of hours i.e. 1 hour, 2 hours, etc.
On pressing a command button the form, an update query is run to populate the [FinishingTime]. If the [StartTime] is chosen to be say 11:00 AM and the number os hours is selected to be say 2 hours, the update query places the value 13:00 for the [FinishingTime]. However if I choose a [StartTime] of say 23:30 PM and select 1 hour, the update query doesn't update the [FinishingTime].
Can anyone help. Here's the SQL code of the update query:-
UPDATE tblTables SET tblTables.BookingTime = Forms!frmGameBooking!TimeValue, tblTables.FinishingTime = Right(DateAdd("s",3600*CInt(Left(Forms!frmGameBooking!No_of_Hours,1 )),Forms!frmGameBooking!TimeValue),8);
The Right function is used to obtain the time portion.
View 8 Replies
View Related
Feb 22, 2005
Hi
I have a combo box on my form. I wish to set the value of a text box on lost focus of the combo to be the value of the combo cbxDateFrom +6 months
The code I am using is
Private Sub cbxDateFrom_LostFocus()
cbxDateTo.Value = [DateAdd("mmmm", 6, me.cbxDateFrom.Value)]
End Sub
But it does not appear to work in any variant I have tried. If it is easier to do it in properties or event builder I don't mind that, I just need the right syntax
Regards
View 5 Replies
View Related
Sep 24, 2004
I am using the following to populate text boxes that are functioning as labels in my report. I am getting an error: #NAME. Do you know what's wrong with this code??
=DateAdd("d",-1,Forms!frmDates!txtEnd)
This prompts me for txtEnd. When I put in the date (which is a parameter from my SQL cross tab query, the values in the report WORK, but the label doesn't. Any ideas?
View 1 Replies
View Related
Mar 10, 2005
I enter this statement on my control source in a text box
of a report for a date field.
=DateAdd("d",1,[startdate]
I get error when I preview the report. I trying to add 1 day
to the date.
Thanks in Advance
View 2 Replies
View Related
Jan 12, 2005
Hi,
I have a field "dimissioni" data/time field and I' m trying validatation rule Dateadd ("d"; [giorni_somma] ; [data_ingresso ]) where "giorni_somma" is a field number integer and data_ingresso is other field Date/Time; my problem is access does't find field "data_ingresso" and "giorni_somma". If I use Dateadd ("d";"2";Now()) access works fine and validation rule is ok.
I hope in help.
Best Regards.
Delfo
View 1 Replies
View Related
Aug 4, 2006
Hi All,
i have a slight problem i have a access table which has the following fields:
Name
Photocard ID
Purchase Date
Photo
Cashsaver Zone
Valid From
Period of Validation
Expiry
the period of validation field has a lookup to another table with the folwing values: 28 Days, 3 Months, 6 Months and Annual.
the valid from date is entered manually.
basically (maybe not uite the right word!) i need the the expiry field to automatically insert the correct expiry date by looking in the valid from date and adding the correct amount of time onto it according to what is selected in the period of validation field.
example:
Valid from date is 01/01/2006
Period of validation is 6 Months
Expiry date should be 01/06/2006 (01/01/2006 + 6 Months)
i came up with the following formula although i know its not really correct and some of the words arent functions at all just to show what is should be based on:
WHERE Period of validation <= DataValue ("28 Days") then DateAdd("d",28, Period of validation)
WHERE Period of validation <= DataValue ("3 Months") then DateAdd("m",3, Period of validation)
WHERE Period of validation <= DataValue ("6 Months") then DateAdd("m",6, Period of validation)
WHERE Period of validation <= DataValue ("Annual") then DateAdd("m",12, Period of validation)
also i am unsure into what box to type this into?
i would greatly apperciate some help
Spindlemania
View 6 Replies
View Related
Aug 1, 2005
This is driving me crazy! What am I missing?
Here's my query:
SELECT tblRelease.ID, tblRelease.Application, tblRelease.Date, DateAdd("d",tblRelease.DateVariance,tblRelease.Date) AS ToDate, tblRelease.Time, tblRelease.Description
FROM tblRelease
WHERE (DateAdd("d",tblRelease.DateVariance,tblRelease.Date)>=[Enter Effective Date])
ORDER BY tblRelease.Application, tblRelease.Date;
I've chopped out a few fields to make it a bit smaller and easier to read.
The problem is that whilst the DateAdd() in the SELECT clause produces exactly the date that I want, the DateAdd() in the WHERE clause does not seem to work. I always get all records no matter what date I enter for [Enter Effective Date]. If I change the WHERE clause to
WHERE (tblRelease.Date>=[Enter Effective Date])
then everything works perfectly and I get different numbers of records depending on the date I enter.
I am entering the date in the form 01/08/2005 and this works for the second variation just fine. It's dd/mm/yyyy in case that's important (my local default).
Anybody see my problem?
View 1 Replies
View Related
Sep 12, 2005
Hi
Sorry if sometihng similar has been posted.
But all I want to do is get this to return data that is a month from now
Gate: IIf(Format([7 PDB],"mmyy")=Format(Date(),"mmyy"),"Move to Delivery")
Any help appreciated
PK
View 1 Replies
View Related