我当前的输入表如下所示
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 相加
它应该遵循当前日历
最佳答案
在数据库中不要使用字符串来表示日期,您应该使用时间戳。
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
关于mysql - 日期字符串操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40018564/