Need help with date conversion - extract Month()
Need help with date conversion/math.
Here's my code. The "Predicted Receive" is a simple CRM date field in a custom module.
current_date() must be return a date-time and extracting "month" from "Predicted Receive" is incorrect...I think.
- SELECT
- Vendors."Vendor Name" as "Vendor",
- Vendors."Monthly Capacity" as "Monthly Capacity",
- sum("Production Tickets".Quantity) as "In Production",
- Vendors."Monthly Capacity" -sum("Production Tickets".Quantity) as "Open Capacity"
- FROM Vendors
- JOIN "Production Tickets" ON Vendors.Id = "Production Tickets".Vendor
- AND "Production Tickets".Vendor IS NOT NULL
- WHERE NOT Vendors."Monthly Capacity" IS NULL
- AND Vendors."Monthly Capacity" > 0
- AND ((Month(current_date()) = Month("Production Tickets"."Predicted Receive")
- AND Year(current_date()) = Year("Production Tickets"."Predicted Receive"))
- OR (Month(previous_nmonth(current_date(), 1)) = Month("Production Tickets"."Predicted Receive")
- AND Year(previous_nmonth(current_date(), 1)) = Year("Production Tickets"."Predicted Receive")))
- GROUP BY Vendors."Vendor Name",
- Vendors."Monthly Capacity",
- Month("Production Tickets"."Predicted Receive"),
- Year("Production Tickets"."Predicted Receive")