【问题标题】:Try to have the Month and the day two digit in Sql尝试在 Sql 中设置月份和日期两位数
【发布时间】:2021-12-22 15:35:54
【问题描述】:

我有一个项目表的 StoredProcedure 我想选择格式为 MMDDYYYY -> 07092021 的“ProjectStartDate”,并且数据将打印在 Excel 电子表格上。 我写的代码是:

 select
 replace(convert(varchar, pp.ProjectStartDate,110),'-','')
 from Project pp

但在电子表格上,月份是 1 位数字 7092021。 请指教,谢谢

【问题讨论】:

  • 这不是 SQL 问题 -- Keeping leading zeros and large numbers
  • 实际上,您最终会发现您不想选择具有特定格式的日期。相反,您会发现您想在表示层(Excel、WinForm、网页、报告等)格式化日期。

标签: mysql sql vb.net


【解决方案1】:

在 MySQL 中你可以使用

date_format(ProjectStartDate,'%m%d%Y')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-15
    • 2013-03-08
    • 1970-01-01
    • 1970-01-01
    • 2012-09-13
    相关资源
    最近更新 更多