Question

Good evening.

How can I calculate periods of 6 months (semesters or a two terms years)?

Explaining: There is a spreadsheet, which I will convert to a MySQL DB, that has the following, relevant, columns Course, Begin and Duration. Course is a string field that combined with the info from another table returns the Duration. The Begin field is year-semester (like 2010-2 is two thousand and ten secound semester) that the course was started. Duration is the number of years.

The format

table1

**Course**       **Begin**
Graduation 1     2010-1

table2

 **Course**      **Duration**
 Graduation 1    4,5

2010-1 means 2010 first semester and 4,5 (actually 4.5 years - four dot five years) means four and a half years, that gives a final date like 2014-1. The fields format, unfortunately, come from another database which I don't have access to change, I just can import the data.

This is probably simple or extremely simple or not.

[Edit] I hope now is correct. [Edit] This will be imported form a first DB, caculated and imported to another DB.

Was it helpful?

Solution

MySQL doesn't have standard support for semesters, so you'd have to convert to months first (quarters are also supported, but working with months is easier regarding date).

This means that you need to replace "2010-1" by "2010-01-01" and "2010-2" by "2010-07-01". This could be done with REPLACE($begin, '-1', '-01-01') and REPLACE($begin, '-2', '-07-01').

For each semester you could add 6 months: DATE_ADD('2010-01-01', INTERVAL 6 MONTH) will return "2010-07-01". Multiply the "duration" by 12, which will give the amount of months you need to shift the "Begin".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top