Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why does a calculated date give the wrong result in an SQL statement?

calculated sql wrong
0
Posted

Why does a calculated date give the wrong result in an SQL statement?

0

Access 2002 Help says: You must use English (United States) date formats in SQL statements in Visual Basic. However, you can use international date formats in the query design grid. (Search with dates in SQL) If you have a form with a date field called txtStartdate, a variable called dtDate of Date datatype, and a table called TempDate with just one column for a date, then the following statements will all insert the correct date in the destination table: dtDate = txtStartDate DoCmd.RunSQL “INSERT INTO TempDate VALUES (#” & dtDate & “#)” from variable DoCmd.RunSQL “INSERT INTO TempDate VALUES (#” & txtStartDate & “#)” from form DoCmd.RunSQL “INSERT INTO TempDate VALUES (#” & Date & “#)” todays date However, if you want to do a calculation on a date (calculate a date a library book is due back, for example) statements such as dtDate = DateAdd(“ww”, 2, Date) add 2 weeks to today ‘dtDate = DateAdd(“d”, 14, Date) alternative method DoCmd.RunSQL “INSERT INTO TempDate VALUES (#” & dtDate & “

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123