I have the following top part of my SQL. I am trying to pull out the current number of days in a month. When I run this I get the error
Invalid operation: cannot cast type integer to timestamp without time zone;
How to I update this so it will pull the number of days in the current month?
SELECT
T1.costcenter_id,
DATEPART(MONTH, GETDATE())as "present month",
DATEPART(DAY, GETDATE())as "present day",
DAY(EOMONTH(GETDATE())) as "days in month",
I used this as a temporary option
CASE
WHEN DATEPART(MONTH, GETDATE()) = 1 THEN 31
WHEN DATEPART(MONTH, GETDATE()) = 2 THEN 28
WHEN DATEPART(MONTH, GETDATE()) = 3 THEN 31
WHEN DATEPART(MONTH, GETDATE()) = 4 THEN 30
WHEN DATEPART(MONTH, GETDATE()) = 5 THEN 31
WHEN DATEPART(MONTH, GETDATE()) = 6 THEN 30
WHEN DATEPART(MONTH, GETDATE()) = 7 THEN 31
WHEN DATEPART(MONTH, GETDATE()) = 8 THEN 31
WHEN DATEPART(MONTH, GETDATE()) = 9 THEN 30
WHEN DATEPART(MONTH, GETDATE()) = 10 THEN 31
WHEN DATEPART(MONTH, GETDATE()) = 11 THEN 30
WHEN DATEPART(MONTH, GETDATE()) = 12 THEN 31
END AS days_in_month
The ultimate goal is to get the percent completion of the month so if the 3rd day of June there is still 93% of the month left. The below query is what I am trying to accomplish.
1-(DATEPART(DAY, GETDATE())/ total days in the month) as % complete