【问题标题】:How to convert to number month to month name?如何将月份名称转换为数字?
【发布时间】:2015-04-28 01:26:47
【问题描述】:

在 sql 数据库中 - 月份中的数据是数字(1,2,3...12)。在我的网页中,我希望它以月份名称显示(Jan、Feb、Mar....Dec)。如何将月份名称转换为数字?

VB.Net

   rs = db.ExecuteSelect("SELECT year,month, run_sequence, pay_code, qty, rate, amount,  " & _
                                      "convert(varchar, effective_date,103) as effective_date " & _
                                      "FROM payTable WHERE id='" & id & "'", Session("CnnStr").ToString)

更新: 找到了我的解决方案。

DATENAME(mm,DATEADD(mm, month-1,0))  as month

【问题讨论】:

    标签: sql sql-server vb.net


    【解决方案1】:

    您可以使用DATENAME 根据您的月份编号获取三位数的月份短名称

    Declare @month int 
    set  @month = 1
    select  Left(DateName( month , DateAdd( month , @month , -1 )),3);
    

    【讨论】:

      【解决方案2】:

      当您选择月份时,请选择 DATENAME(mm,month)。

      【讨论】:

      • DATENAME(mm,DATEADD(mm, month-1,0)) as month
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-07
      • 1970-01-01
      • 2012-11-26
      • 1970-01-01
      • 2011-03-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多