【问题标题】:Date string Manipulation日期字符串操作
【发布时间】:2016-10-13 10:33:16
【问题描述】:

我当前的输入表如下所示

Current_Day billing_day
Oct-13      14
Oct-13      15
Oct-13      16
Oct-13       1
Oct-13       8
Oct-13      12

我希望结果表如下所示

Current_Day billing_day Start_date  End_date
Oct-13      14          Oct-13      oct-14
Oct-13      15          Oct-13      oct-15
Oct-13      16          Oct-13      oct-16
Oct-13       1          Oct-13      nov-1
Oct-13       8          Oct-13      nov-8
Oct-13      12          Oct-13      nov-12

有没有办法或函数在 MySQL 中实现这一点?

编辑:

如果 billing_day 是 14,它应该显示最近的即将到来的日历日期 例如:14 表示 oct-14,1 表示 Nov-1,因为 oct-1 已经过去了。

结果 End_date 不应是 billing_day + Current_day 的加法

它应该遵循当前日历

【问题讨论】:

  • End_date 来自哪里?好的。知道了。你想在表格中更新它还是仅仅显示?
  • End_date 必须来自 billing_day,例如:14 变为 oct-14
  • 显示并更新到表格:)
  • 我已经更新了我的答案。看看有没有帮助。

标签: mysql string date


【解决方案1】:

在数据库中不要使用字符串来表示日期,您应该使用时间戳。

https://dev.mysql.com/doc/refman/5.5/en/datetime.html

函数日期和时间

https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-25
    • 2021-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多