【问题标题】:postgresql query to return the day of the week of the first day of the month two years from todaypostgresql查询返回从今天起两年后一个月的第一天的星期几
【发布时间】:2020-10-17 19:32:27
【问题描述】:

我用postgresql解决了这个问题,查询返回两年后一个月的第一天的星期几。我可以用下面的查询来解决它,但我不确定我的查询是否正确,我只是想确定

select cast(date_trunc('month', current_date + interval '2 years') as date)

【问题讨论】:

    标签: sql postgresql date select truncate


    【解决方案1】:

    您正确计算了两年后一个月的第一天:

    date_trunc('month', current_date + interval '2 years')
    

    如果想要一周中的对应天,可以使用extract()

    extract(dow from date_trunc('month', current_date + interval '2 years'))
    

    这会为您提供介于 0(星期日)和 6(星期六)之间的整数值

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-20
      • 2011-07-07
      • 1970-01-01
      • 2015-07-09
      • 2015-07-04
      • 1970-01-01
      • 1970-01-01
      • 2013-08-30
      相关资源
      最近更新 更多