Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm working on a SQL project where I give a year as input and I have to divide the year into trimesters . I want to use the DATEPART function but i don't know how . Could you give me an example specifically for trimesters ? The code below returns the selected month .
Thank you in advance.

What I have tried:

SELECT DATEPART(month, '2017/08/25') AS DatePartInt;
Posted
Updated 29-Dec-19 4:05am

 
Share this answer
 
Since a US "trimester" is a period of 12 - 13 weeks during which you are supposed to be in school (assuming it's not a medical trimester which is pregnancy related and follows no schedule other than "the first trimester starts at conception") DATEPART won;t help you divide a year into anything.

What you need to do is look at your homework question in detail, and work out exactly what you are supposed to do. I'd assume that you are supposed to be given a year and work out when each of the school periods is likely to start and end. That'll take a little research: there are probably guidelines that school districts follow to decide the start and end day, but they will be a "movable feast" in that it won't be "Jan 14th" every year for example.

So:
1) Find out exactly what you are supposed to be doing.
2) Find out what the rules are that apply to what you are doing.

Then try it on paper by hand, and work out rules you can follow to accurately fulfil both of the above. When you have that, it should be fairly obvious what you need to do to implement it in SQL - but it's not going to be "just use DATEPART" that will cover it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900