SELECT medicalDate
FROM PilotMedical
WHERE pilotID = '1'
This will get the date of the medical exam. However, I need to return when this medical exam expires, which is one year from the date, and the last day of the month. For example, if I get a medical exam on January 12th, 2012, it will expire January 31st, 2013.
medicalDate is a “date” type.
How can I do this in SQL? Basically I want to have it return 1/31/2013 for a medical exam any time in January 2012.
If not, I guess I can do it in VB. I’m much more interested in learning how to do it in VB as I don’t plan on working with VB the rest of my life
EDIT:
This will get the last day of the month
--Last Day of Any Month and Year
DECLARE @dtDate DATETIME
SET @dtDate = '8/18/2007'
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@dtDate)+1,0))
LastDay_AnyMonth
ResultSet:
LastDay_AnyMonth
———————–
2007-08-31 23:59:59.000
Now looking for how to add a year to this
This demonstrates one way to do it:
Step 1: Create a new date in the same month, next year, but on the 1st.
Step 2: Adds one month
Step 3: Subtracts one day