SQL 生成公曆和農曆對照數據續--创建萬年曆查找各種周期性節日數據 .




---sql server 2005  測試 塗聚文 捷為工作室,締友計算機信息技術有限公司
---查找公曆節日
--select (@year-GooddayStaryear) as Gyear,GooddayContent from GoodDaysList where @year>=GooddayStaryear and GooddayStarmoth=@month and GooddayStardayorWeek=@week and GooddayWeekdays=@Day  and GooddayUidKey='F0FAFC87-F492-455F-B56E-358917658B6E'
select * from GoodDaysList

declare @setDate datetime,@year int,@month int,@day int,@weeks int,@weekday int,@GooddayUidKey Uniqueidentifier
set @setDate='2012-12-01' --設置現在的日期
set @year=Year(@setDate)
set @month=Month(@setDate)
set @day=DAy(@setDate)
set @weeks=DAy(@setDate)
set @GooddayUidKey='D9C5D984-6AEB-4EE4-B332-82F7E878D539'
select @year as '日',@month as '月',@day as '日'

select (@year-GooddayStaryear) as Gyear,GooddayContent from GoodDaysList where @year>=GooddayStaryear and GooddayStarmoth=@month and GooddayStardayorWeek=@weeks and GooddayUidKey=@GooddayUidKey






---查找農日節日 測試 塗聚文 捷為工作室,締友計算機信息技術有限公司
---1700年之前的节日需要用sql server 2008之後版本才行,Access 也行
select  dbo.fn_GetLunarNumber('2012-06-23')
--農曆查公曆
select dbo.fn_GetDate('2012-05-05')

 select * from dbo.GoodDayClass

declare @setDate datetime,@Lunaryear int,@Lunarmonth int,@Lunarday int,@weeks int,@weekday int,@GooddayUidKey Uniqueidentifier,@LunarDate datetime
set @setDate='2012-06-23' --設置現在的公曆日期
select @LunarDate=dbo.fn_GetLunarNumber(@setDate)
set @Lunaryear=Year(@LunarDate)
set @Lunarmonth=Month(@LunarDate)
set @Lunarday=DAy(@LunarDate)
set @weeks=DAy(@LunarDate)
set @GooddayUidKey='F25835BF-3918-4201-BB8D-BD82F737EF8A'
select @LunarDate as '農日日期',@Lunaryear as '農曆年',@Lunarmonth as '農曆月',@Lunarday as '農曆日'
select (@Lunaryear-GooddayStaryear) as Gyear,GooddayContent from GoodDaysList where @Lunaryear>=GooddayStaryear and GooddayStarmoth=@Lunarmonth and GooddayStardayorWeek=@weeks and GooddayUidKey=@GooddayUidKey

select * from dbo.GoodDaysList
---查找周節日

declare @setDate datetime,@year int,@month int,@day int,@weeks int,@weekday int,@GooddayUidKey Uniqueidentifier,@weekdayname varchar(10)
set @setDate='2012-05-06' --設置現在的日期
set @year=Year(@setDate)
set @month=Month(@setDate)
set @day=DAy(@setDate)
select @weeks=DATEPART(WEEK,@setDate)-DATEPART(WEEK,DATEADD(MONTH,DATEDIFF(MONTH,0,@setDate),0))+1  --月中周幾
select @weekday=DATEPART(weekday,@setDate)-1 --周幾(0星期天,1星期一,2星期二)
select @weekdayname=DATENAME(weekday,@setDate) --周幾
set @GooddayUidKey='F25835BF-3918-4201-BB8D-BD82F737EF8A'
select @year as '年',@month as '月',@weeks as '月中第幾周',@weekday as '周幾',@weekdayname as '周幾'
select (@year-GooddayStaryear) as Gyear,GooddayContent from GoodDaysList where @year>=GooddayStaryear and GooddayStarmoth=@month and GooddayStardayorWeek=@weeks and GooddayWeekdays=@weekday and GooddayUidKey=@GooddayUidKey


--查找年中第多少日的節日(如程序員節) 其它節日在此略


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值