存储过程来计算一个月中的天数 [英] stored procedures to count days in month

查看:182
本文介绍了存储过程来计算一个月中的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何需要帮助的人,我都需要一个存储过程,在存储五天或一个月后,我将使用它来返回表中的每个数据,所以我的问题是计算天数然后检索我想要的任何人的数据help

Anyone with help good people i need a stored procedure that i will use it to return every data in the table after five days or month after stored, so my problem is to count the days then retrieve the data that i want anyone with help

推荐答案

它将返回当月的天数
it will return the number of days in the current month
declare @dt datetime
set @dt = getdate()

select
	DT = @dt,
	[Days in Month] =day(dateadd(mm,datediff(mm,-1,@dt),-1))



或者您可以尝试



or you can try

datediff(day, dateadd(day, 1-day(@date), @date),
              dateadd(month, 1, dateadd(day, 1-day(@date), @date)))


在此处无法正常使用.

这是询问者的期望:
1. 先尝试您要做什么!您可能会发现它并不难.
2.制定看起来像问题/无法解决的问题.

试试看,告诉他们是否遇到问题.
成员将很乐意为您提供帮助.


现在,执行以下步骤:
1.在表格中定义日期列
2.插入任何新记录时,用插入的DateTime填充日期列值
3.从数据库检索数据时,请使用WHERE子句
4. WHERE子句将由定义的日期列驱动.找到当前日期时间和存储的日期时间之间的差异.驱动逻辑将是日期时间与给定数字的差异(假设是5天)

试试吧.
It does not work like this here.

Here is what is expected of enquirers:
1. TRY first what you want to do! You may find that it''s not that hard.
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.


For now, steps:
1. Define a date column in your table
2. When you insert any new record, populate the date column value with the DateTime of insertion
3. While retrieving data from DB, use a WHERE clause
4. WHERE clause will be driven by the date column defined. Find the difference in current datetime and the datetime stored. Driving logic would be the difference of the datetime from a given figure (let say 5 days)

Try out.


这篇关于存储过程来计算一个月中的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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