Date Arithmetic in Access 2016 Web Application - ms-access

I am trying to write a simple expression in Access 2016 web. I want to do this: DateAdd(Day,7,[txtStartDate]) but I keep getting an error message that Access cannot interpret this expression.
Does anyone know how to do this in Access 2016 web forms?

That's because your syntax is wrong. To add 7 days to [txtStartDate], you can use one of the following:
DateAdd("d", 7, [txtStartDate])
OR
[txtStartDate] + 7
OR
DateAdd("w", 1, [txtStartDate])
(7 days is one week)

Related

Can't get the Today() function to work properly in MS Access 2016 Custom Web App

I'm trying to setup a query that will show me all of the records in a particular table where the listed expiry date is either in the past or upcoming in the next 6 months (approximately).
At the moment, I have the "Expiry" field added to my query and the 'Criteria' as .
When I try to save the query, I get the following message:
Access can't evaluate an expression or convert data because data types aren't compatible with each other.
TECHNICAL DETAILS
Correlation ID: ae68949d-3041-3000-0984-71635f8fd670
Date and Time: 7/28/2016 6:54:34 PM
I've tried searching the web for a solution, but most websites refer to the Date() function that doesn't seem to be available in the Access 2016 Custom Web App. When I take out the "+180", it works fine but obviously doesn't give me what I need.
Any help would be appreciated.
=============================
UPDATE:
Some users have asked for my SQL and Table Design details. I don't seem to have any way of accessing the SQL View (the option doesn't appear), but here's a copy of my table view:
Access Query Table Design
In the table, 'Active' is a Yes/No field and 'Expiry' is Date/Time.
Try
< DateAdd(Day, 180, Today())
as criteria.
According to https://msdn.microsoft.com/en-us/library/office/jj249452.aspx this should work in a custom web app.
Error says that you have two different date types and they can't be compared. so, as the Today() returns only the Date with 12:00 pm, I can guess that your other "Expiry" Field is a datetime type. So, you can do either: use Format function to convert datetime to date like this
Format([2/22/2012 12:00 PM],"dd/mm/yyyy")
or use Now() function which returns datetime,
or Share your Code :)

can't get SSRS 2008 IIF statement with DatePart to work

I'm getting an error when I use the statement below. I'm using an IIF statement to get the correct week number. The week numbers are different for 2016 than other years so my old expression is returning one week number later than it should -- the old: =DatePart(DateInterval.WeekOfYear, Fields!REQ_DATE.value).
what I have written but am getting an error and I cannot figure out what the problem is:
=IIF(=DatePart(DateInterval.Year, Fields!REQ_DATE.Value) =
“2016”,=DatePart(DateInterval.WeekOfYear, Fields!REQ_DATE.Value) –
1,=DatePart(DateInterval.WeekOfYear, Fields!REQ_DATE.Value))
basically, if the year of the field REQ_DATE is 2016, I want the WeekOfYear for REQ_DATE - 1; else just the WeekOfYear.
can anyone help me? thank you!
You don't have to use = for every function you call in an expression, use the = only once at the beginning of the whole expression.
Try:
=IIF(DatePart(DateInterval.Year, Fields!REQ_DATE.Value) =
"2016",DatePart(DateInterval.WeekOfYear, Fields!REQ_DATE.Value) –
1,DatePart(DateInterval.WeekOfYear, Fields!REQ_DATE.Value))

How to get MySQL to return the correct year number for "week 53 of 2012" using "mode 7"

How would I get MySQL to tell me that '2013-01-01' is week number 53 of 2012?
I'm using mode 7 for the definition of a week.
I can get the week number easily enough by using WEEK('2013-01-01', 7)
The problem is that, of course, YEAR('2013-01-01') returns 2013.
The YEARWEEK function lets you pass the mode to it as well. The only downside is that it returns the year and week-in-year combined together:
SELECT YEARWEEK('2013-01-01', 7);
>> 201253
You can get around that with SUBSTRING, though, if you really need just the year separately:
SELECT SUBSTRING(YEARWEEK('2013-01-01', 7), 1, 4);
>> 2012

DateAdd function in MS Access

I am trying to use the DateAdd function in Access 2007.
My end goal is to have 5, 10, or 15 years added to the date coming in from the table if another field [Type] is a certain keyword.
For reference NewDate = DateAdd("yyyy",10,[Type]), and I know I'll have to come up with more code for the database to decide how many years to add to it. Is this even possible in a query in Access 2007?

How Can I Perform Date Comparisons in Access 2013 Query Criteria?

I have a date field in my table, and I'm writing a query in Access 2013 to select all items where the date is between 7-days-ago and 30-days-in-the-future.
Currently, I've added the following as "criteria" under the date field:
>=Today()-7 And <=Today()+30
But I get the following error when I try to save the query:
I've tried using DateDiff (as I have in other scenarios) but it tells me that I'm not allowed to use that type of expression as criteria.
EDIT: This is an Access 2013 custom web app for SharePoint 2013, and all the available functions and syntaxes appear to be different from those available in a desktop database file.
You might be confusing with the Excel function named TODAY(). In Access it is called Date().
You can also use Between..And.
Between Date()-7 And Date()+30
Added In response to advice about using SharePoint:
I don't use SharePoint, but might guess that you need to specify the field explicitly:
fieldName >= Today()-7 And fieldName <= Today()+30
you might use brackets to make the statement clearer:
(fieldName >= Today()-7) And (fieldName <= Today()+30)