sql 时间的取值

来源:百度知道 编辑:UC知道 时间:2024/06/17 17:20:33
定义 时间字段
dim BeforeMonth,ThisMonth,BeforeSeason,ThisSeason,BeforeHalf,ThisHalf,BeforeYear,ThisYear

比如 现在时间 Now() 那么要怎么样取 这个时间所在的月、季、半年、整年,以及去年的月、季、半年、整年。指的是一个时间段哦!!!
例如:2009-8-15 00:00:00 那么根据这个时间要取的是:
==去年==
月份:2009-08-01 00:00:00 - 2009-08-31 23:59:59 BeforeMonth=?
季度:2009-06-01 00:00:00 - 2009-09-30 23:59:59 BeforeSeason=?
半年:2009-06-01 00:00:00 - 2009-12-31 23:59:59 BeforeHalf=?
月份:2009-01-01 00:00:00 - 2009-12-31 23:59:59 BeforeYear=?
==今年==
月份:2009-08-01 00:00:00 - 2009-08-31 23:59:59 ThisMonth=?
季度:2009-06-01 00:00:00 - 2009-09-30 23:59:59 ThisSeason=?
半年:2009-06-01 00:00:00 - 2009-12-31 23:59:59 ThisHalf=?
月份:2009-01-01 00:00:00 - 2009-12-31 23:59:59 ThisYear=?
是 sql server

楼主的是Access库?
用format
select format(now(),'yyyy-mm')

问题补充:

是 sql server
---------
实现方法
时间条件用 between
convert(varchar(7),日期,120)--取看月
当前日期用getdate()

就这么个问题0分? 你这个问题不是一句话两句话能说明白的,你要尊重大家的劳动成果才行

如果你要找交流平台请去CSDN问,大家都很忙的