如何使用月份和时间准备一个完整的日期年 [英] How to prepare a full date using month & year

查看:72
本文介绍了如何使用月份和时间准备一个完整的日期年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个月和一个月一年,使用我想显示的总日期是-01,时间是0'。



如何实现这个



ex:



month -3



year-2013



i希望显示这是''2013-03-01 00:00:00'的行军的第一天'



我正在使用类似的东西,但这并没有给出确切的结果

I have a Month & year , using that i want to display total date with day is -01 and time is 0''s.

How to achieve this

ex:

month -3

year-2013

i want to display this is first day of march like ''2013-03-01 00:00:00''

i''m using something like this but this is not given exact result

cast(year(release_date) as char(5))+'-'+cast(month(release_date) as char(2))+'-'+'01 00:00:00'





使用本月返回3,所以t他的结果变得像2013-3-01 00:00:00,但这格式不正确...



using this month returns 3, so the result becomes like this 2013-3-01 00:00:00, but this is not in correct format na.....

推荐答案

我的自我解决这个问题...



使用这个

My self to resolve this issue...

Using this
convert (datetime ,cast(year(release_date) as varchar(4))+right('00'+cast(month(release_date) as varchar(2)),2)+right('00' + cast(@day as varchar(2)),2)) AS Release_Date





对于其他一些对此感到困惑的人可能会有所帮助同样的问题..



It might be helpfull to some other , who are confusing about the same issue..


嗨......



非常简单......试试这个:-) :-) :-)

Hi....

Its very simple ... try this :-) :-) :-)
DECLARE @CurDate DATETIME=GETDATE()
 
SELECT CONVERT(DATETIME,CAST(YEAR(@CurDate) AS VARCHAR(5))+'-'+CAST(MONTH(@CurDate)AS VARCHAR(5))+'-01',101) 'ReqDate'

ReqDate
----------------------
2013-03-01 00:00:00.000


检查:





SELECT CAST(年份(GETDATE())AS VARCHAR( 4))+'' - ''+ CAST(月份(GETDATE())AS VARCHAR(4))+'' - ''+ CAST(01 AS VARCHAR(2))+''''+ CAST(''' 00:00:00''AS VARCHAR(10))
Check this:


SELECT CAST(YEAR(GETDATE())AS VARCHAR(4))+''-''+ CAST( MONTH(GETDATE())AS VARCHAR(4))+''-''+ CAST(01 AS VARCHAR(2))+'' ''+CAST(''00:00:00'' AS VARCHAR(10))


这篇关于如何使用月份和时间准备一个完整的日期年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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