DateAdd Function in a Computed Querry (1 Viewer)

sandros

New member
Local time
Today, 13:41
Joined
Apr 8, 2016
Messages
7
Hello
I am trying to use the dateadd function in an expression in a computed querry.
What i am trying to do, is to use this function, to create a collumn that increases the date of a table's field (DateEntry), for five years.
The syntax is Expr1: DateAdd('y',5,[Datentry]) but it seems that comma, after 'y', creates a problem which i cannot bypass.
Can anyone help please?
 

JHB

Have been here a while
Local time
Today, 22:41
Joined
Jun 17, 2012
Messages
7,732
The syntax is Expr1: DateAdd('y',5,[Datentry]) but it seems that comma, after 'y', creates a problem which i cannot bypass.
Can anyone help please?
Depending of from where in the world you're - you've to use ; instead of a comma.
 

sandros

New member
Local time
Today, 13:41
Joined
Apr 8, 2016
Messages
7
Depending of from where in the world you're - you've to use ; instead of a comma.
Thank you for the reply
I am from Greece.
When i try to use ; Access changes the original expression to this :
Expr1: DateAdd('\y';5;[Datentry])
which returns an error result when i run the querry
 

Minty

AWF VIP
Local time
Today, 21:41
Joined
Jul 26, 2013
Messages
10,379
Try using double quotes around the "y" ?
DateAdd("y";5;[Datentry])
 

Minty

AWF VIP
Local time
Today, 21:41
Joined
Jul 26, 2013
Messages
10,379
Have you tried going back to the comma with the double quotes ? DateAdd("y",5,[Datentry])
 

Minty

AWF VIP
Local time
Today, 21:41
Joined
Jul 26, 2013
Messages
10,379
Is DateEntry definitely a date?
 

sandros

New member
Local time
Today, 13:41
Joined
Apr 8, 2016
Messages
7
Is DateEntry definitely a date?
The field is definetely a date, the problem is at expression syntax where comma is not accepted. But anything else, changes the expression in a way that returns an error. :banghead::banghead:
I don't know if there are any Access settings that define the manipulation of comma or semicolon
 

Minty

AWF VIP
Local time
Today, 21:41
Joined
Jul 26, 2013
Messages
10,379
What delimiters do you normally use for other functions ? IIf ? or Format ?
 

Grumm

Registered User.
Local time
Today, 22:41
Joined
Oct 9, 2015
Messages
395
Does a delimiter in VBA changes from location ? If it is grats to the guys who wrote the compiler... the official help say to use "," for that specific function.
But I can be wrong
 

Minty

AWF VIP
Local time
Today, 21:41
Joined
Jul 26, 2013
Messages
10,379
I hope not - wouldn't make for much portability! I completely missed the mal-formed "yyyy" bit...
 

JHB

Have been here a while
Local time
Today, 22:41
Joined
Jun 17, 2012
Messages
7,732
..
I don't know if there are any Access settings that define the manipulation of comma or semicolon
No it is the location, in Denmark we use the, as decimal point/separator.
Here is a link to which countries use . or , as decimal points - half down the document.
https://en.wikipedia.org/wiki/Decimal_mark
Does a delimiter in VBA changes from location ? If it is grats to the guys who wrote the compiler... the official help say to use "," for that specific function.
But I can be wrong
Yes you're wrong - I've wasting to much time in the start using MS-Access to forget it. :(
Below is a picture of the error message if you use a comma.

Here with a ;, (no errors).


But the SQL-String is with a , (so you've to be very aware of where to use , or ; )
Code:
SELECT DateAdd("y",5,[Date of Loan]) AS Expr1
FROM LoanT;
 

Attachments

  • CommaOr1.jpg
    CommaOr1.jpg
    60.9 KB · Views: 586
  • CommaOr.jpg
    CommaOr.jpg
    11.3 KB · Views: 191

leanpilar

Registered User.
Local time
Today, 22:41
Joined
Aug 13, 2015
Messages
94
use your immediate window to test it helps me a lot
?dateadd("yyyy",5,date())
09.04.2021.
?dateadd("y",5,date())
14.04.2016.
 

Grumm

Registered User.
Local time
Today, 22:41
Joined
Oct 9, 2015
Messages
395
I'm from Belgium and we use the , also as decimal point. I haven't ran into a similar problem yet (Maybe a good time for me to see this post before pulling my hair out)

Most of the time I use calculated fields on the form itself. And if i need SQL i write the full statement in VBA code. I don't like the macro's and wizardry things
 

sandros

New member
Local time
Today, 13:41
Joined
Apr 8, 2016
Messages
7
As it is evident when i use the semicolon, Access adss a "switch \", which returns an error message. :banghead::banghead:
expr1: DateAdd("\y";5;[Datentry])
 

JHB

Have been here a while
Local time
Today, 22:41
Joined
Jun 17, 2012
Messages
7,732
Then do it backwards:
Create a new query, choose the table.
From the menu - choose "SQL View", copy the below into it, (remember to insert your table name):
DateAdd("y",5,[Datentry])
SELECT DateAdd("y",5,[Datentry]) AS Expr1
FROM YourTable;
Then choose "Design View" from the menu - what do you get - is it with a , or a ;?
But when you want to add 5 years, then you need 4 y's, DateAdd("yyyy",5,[Datentry]).
 

sandros

New member
Local time
Today, 13:41
Joined
Apr 8, 2016
Messages
7
Then do it backwards:
Create a new query, choose the table.
From the menu - choose "SQL View", copy the below into it, (remember to insert your table name):
DateAdd("y",5,[Datentry])

Then choose "Design View" from the menu - what do you get - is it with a , or a ;?
But when you want to add 5 years, then you need 4 y's, DateAdd("yyyy",5,[Datentry]).
I thing we have the solution. This tip really worked out. I want to thank you for your time, you really help me at my work!:)
 

JHB

Have been here a while
Local time
Today, 22:41
Joined
Jun 17, 2012
Messages
7,732
You're welcome, good luck. :)
 

Users who are viewing this thread

Top Bottom