Inactive User
8 years agoposts count of last 7 days
Hello everybody!
I'm trying to write a custom component to get the count of threads posted within the last 7 days or so using APIv2. Here's what i did!
<#assign today = .now?long />
<#assign minus7days= today - (1000 * 24 * 60 * 60 * 7) />
<#assign since7days= aWeekBack?string["yyyy-MM-dd"] + "T00:00:00-00:01" />
<#local query = "SELECT count(*) FROM messages WHERE depth = 0 AND post_time > " + since7days />
This doesn't return the right count. Can someone pls help me with the right approach?
Best
This should work as well
<#assign now = datesupport.now /> <#assign today = now.millisecondsAsString?number?number_to_datetime?iso("Europe/Zurich") /> <#assign lastWeek = now.addWeek(-1).millisecondsAsString?number?number_to_datetime?iso("Europe/Zurich") /> <#assign query = "SELECT count(*) FROM messages WHERE post_time > " + lastWeek + " AND post_time < " + today + "ORDER BY post_time ASC" /> <#assign data = rest("2.0", query) />