Get a list of dates between two dates

后端 未结 20 2154
醉梦人生
醉梦人生 2020-11-22 00:26

Using standard mysql functions is there a way to write a query that will return a list of days between two dates.

eg given 2009-01-01 and 2009-01-13 it would return

20条回答
  •  面向向阳花
    2020-11-22 01:04

    For Access (or any SQL language)

    1. Create one table that has 2 fields, we'll call this table tempRunDates:
      --Fields fromDate and toDate
      --Then insert only 1 record, that has the start date and the end date.

    2. Create another table: Time_Day_Ref
      --Import a list of dates (make list in excel is easy) into this table.
      --The field name in my case is Greg_Dt, for Gregorian Date
      --I made my list from jan 1 2009 through jan 1 2020.

    3. Run the query:

      SELECT Time_Day_Ref.GREG_DT
      FROM tempRunDates, Time_Day_Ref
      WHERE Time_Day_Ref.greg_dt>=tempRunDates.fromDate And greg_dt<=tempRunDates.toDate;
      

    Easy!

提交回复
热议问题