Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

Calculate number of days in query

Experts,
Here a query I'm developing that calculates a future date based upon a date in my table.
I would like to be able to subtract maturityDate from dateID to show the number of actual days.
One final thing. Will the query as presented take into account leap years? If not, how does one handle leap years.

SELECT tblDate.DateID, DateSerial(Year([dateID]),Month([dateID]),Day([DateID])+30) AS maturityDate
FROM tblDate;
0
Frank Freese
Asked:
Frank Freese
  • 2
1 Solution
 
Rey Obrero (Capricorn1)Commented:
<Will the query as presented take into account leap years? > Yes

<I would like to be able to subtract maturityDate from dateID to show the number of actual days>

the actual days difference is already in your query (30)

anyway

SELECT tblDate.DateID, DateSerial(Year([dateID]),Month([dateID]),Day([DateID])+30) AS maturityDate, DateDiff("d",[DateID],[maturityDate]) as NDays
FROM tblDate
0
 
Frank FreeseAuthor Commented:
thanks cap: I know my actual days are in the query, but my boss wants to see the Access calculation to reassure himself the query is right.
0
 
Frank FreeseAuthor Commented:
thank you
0
 
OMC2000Commented:
maturityDate was defined in the same statement and cannot be used here as operand of select expression. And why we need functions here I always use direct operations and it used to work

SELECT tblDate.DateID, DateID+30 AS maturityDate, SomeDateField - SomeOtherDateField as NDays
FROM tblDate
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now