如何获得两个日期之间不同的不同日期 [英] How to get different distinct dates between the two dates

查看:75
本文介绍了如何获得两个日期之间不同的不同日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.. !!
我有两列.... from_date和to_date的数据类型为datetime.
我想要一个介于from_date和to_date之间的日期列表.

如何在查询中执行此操作?.

欢迎任何澄清,建议或链接..!!

Hello everyone..!!
I have two columns....from_date and to_date having their datatype as datetime.
I want to have a list of dates falling in between from_date and to_date.

How can i do it in a query..?

Any clarification,suggestion or links are welcomed..!!

推荐答案

Vaibhav难吗,
好吧,看看这个:

Is it that much hard Vaibhav,
Well have a look on this:

SELECT * FROM tableName WHERE DtcolumnName >= @From_Date AND DtcolumnName <= @To_Date


嘿,
试试这个
hey,
try this
SELECT  distinct
      colName
  FROM tblName
  where colName between  fromDate and toDate



希望对您有帮助
祝你好运
快乐编码:)



Hope it will help u
best Luck
Happy Coding:)




试试这个,
Hi,

Try this,
WITH date_range (calc_date) AS (
    SELECT DATEADD(DAY, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP) - 6, 0)
        UNION ALL SELECT DATEADD(DAY, 1, calc_date)
            FROM date_range
            WHERE DATEADD(DAY, 1, calc_date) < CURRENT_TIMESTAMP)
SELECT calc_date
FROM date_range;



用您的日期替换CURRENT_TIMESTAMP..
一切顺利.



replace the CURRENT_TIMESTAMP with your dates..
All the best..


这篇关于如何获得两个日期之间不同的不同日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆