Reputation: 407
My current input table looks like below
Current_Day billing_day
Oct-13 14
Oct-13 15
Oct-13 16
Oct-13 1
Oct-13 8
Oct-13 12
I want the resultant table to look as below
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
Is there a way or a function to achieve this in MySQL?
Edit:
If the billing_day is 14, it should show nearest upcoming calendar date Ex: 14 means oct-14, 1 means Nov-1 since oct-1 has already passed.
resultant End_date should not be the addition of billing_day + Current_day
It should follow the current calendar
Upvotes: 0
Views: 49
Reputation: 715
In database don't use String to represent date you should use TimeStamp.
https://dev.mysql.com/doc/refman/5.5/en/datetime.html
Function Date and Time
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
Upvotes: 1