【问题标题】:Need to calculate the current date till end year?需要计算当前日期到年底?
【发布时间】:2015-07-09 06:44:04
【问题描述】:

我正在自动生成当前具有 3 个日期设置参数的报告,用户输入。请注意,我们的日期采用 yyyymmdd 格式。

我们希望第一组从当前日期开始: ToText(CurrentDate, 'yyyyMMdd') 直到年底。我可以硬编码 20151231 但不希望这样做。您将如何为一年中的最后一天编写此脚本?

【问题讨论】:

  • 为什么不直接去 Year + '1231' ?
  • 那很好。没想到。

标签: sql crystal-reports-2008


【解决方案1】:

假设您使用的是近期的 SQL Server:

  • 当前日期:
    select today = convert(date, current_timestamp )

  • 当月的第一天:
    select first_of_month = convert(date, dateadd(day, 1-day(current_timestamp) , current_timestamp ) )

  • 当月最后一天:
    select last_of_month = convert(date, dateadd(day, 1-day(dateadd(month,1,current_timestamp)) , dateadd(month,1,current_timestamp) ) )

  • 当年的第一天:
    select first_of_year = convert(date, dateadd(day, 1-datepart(dayofyear,current_timestamp) , current_timestamp ) ) ,

  • 当年的最后一天:
    select last_of_year = convert(date, dateadd(year,1, dateadd(day, -datepart(dayofyear,current_timestamp) , current_timestamp ) ) )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-04
    • 2014-05-30
    相关资源
    最近更新 更多