首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在用户定义函数中从字符串转换日期和/或时间时转换失败

在用户定义函数中从字符串转换日期和/或时间时转换失败
EN

Stack Overflow用户
提问于 2019-05-22 08:49:20
回答 1查看 61关注 0票数 -1

处理应该返回日期的函数。但是我得到了这个错误,我不确定如何修复它

代码语言:javascript
运行
复制
if (@flow_date = eomonth(@flow_date) or day(@flow_date) < day(@lMaturityDate)) begin
                    set @lMaturityDate = eomonth(@lMaturityDate);
                end

                else begin


                    if  month(@lMaturityDate) < 10 BEGIN
                        set @month=concat('0',month(@lMaturityDate));

                    end
                    else Begin
                        set @month=month(@lMaturityDate);

                    END

                    set @lMaturityDate =convert(date,concat(year(@lMaturityDate),'-',@month,'-',day(@flow_date)))
            end

        END
            return isnull(@lMaturityDate,null);

    END

导致错误的示例代码,我只是注意到它抛出错误的时间长于10个月

代码语言:javascript
运行
复制
declare @month varchar(40);
 declare @lMaturityDate date = '2019-11-31'
 declare @flow_date date = '2019-04-25'

if  month(@lMaturityDate) < 10 BEGIN
                    set @month=concat('0',month(@lMaturityDate));

                end
                else Begin
                    set @month=month(@lMaturityDate);

                END
set @lMaturityDate  =convert(date,concat(year(@lMaturityDate),'-',@month,'-',day(@flow_date)))
select  @lMaturityDate
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56247968

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档