Link to home
Start Free TrialLog in
Avatar of benthompson22
benthompson22

asked on

graphing database entries over a 24 hour period

I'm trying to graph, via a bar graph and some code I found here on the forums, the number of database entries (in this case news stories) in 30 minute increments over a 24 hour period. For some reason it's graphing everything twice (for example, it's graphing an entry that was made today at 3pm on the graph at BOTH 3PM and 3AM!) Please help! It's driving me crazy!! The date/time entry (DateTimePosted) was entered into the database using CreateODBCDateTime(Now()). If you need to know any other information please let me know!
<cfparam name="URL.author" default="all" type="any">
<cfif URL.author IS "all">
<cfset AuthorName = "Big Radio News">
<cfelse>
<cfquery name="NewsUsers" datasource="WEKZdata">
SELECT * FROM NewsUsers
WHERE UserID = #URL.Author#
</cfquery>
<cfset AuthorName = NewsUsers.FirstName>
</cfif>
<CFPARAM name="URL.DATE" Default="#CreateDate(Year(Now()),Month(Now()),Day(Now()))#">
<cfset DATE = #CreateODBCDate(URL.DATE)#>
<CFPARAM NAME="timeslices" DEFAULT="48">
<CFPARAM NAME="slice_minutes" DEFAULT="#1440/timeslices#">
 
<CENTER>
<cfchart format="jpg" chartwidth="900" chartheight="350" showlegend="yes" xaxistitle="Vote time: " yaxistitle="Number of Stories: " >
    <cfchartseries type="bar" itemcolumn="Stories Posted on #DateFormat(DATE,"YYYY/MM/DD")#" >
    <cfchartseries type="bar" itemcolumn="Stories Posted By #AuthorName#" >
 
<!--- Loop through DAYS and find stories for each day --->
<CFLOOP INDEX="preiod_num" FROM="1" TO="#timeslices#">
   <!--- Set date variables --->
   <CFSET PERIOD_START = DateAdd("n", preiod_num*slice_minutes, DATE)>
   <CFSET PERIOD_END = DateAdd("n", slice_minutes, PERIOD_START)>
 
      <!--- The Graph gets its data from the NewsStory table  --->
 
<!-- if the user wants the data from all users -->
 
  <cfif URL.author IS "all">
    <CFQUERY NAME="DownloadInfo" DATASOURCE="WEKZdata">
      SELECT * FROM NewsStory
      WHERE DateTimePosted BETWEEN #PERIOD_START# AND #PERIOD_END#
   </CFQUERY>
   
  <cfelse>
<!-- if the user only wants the data for one specific user (author) -->  
 
  <CFQUERY NAME="DownloadInfo" DATASOURCE="WEKZdata">
      SELECT * FROM NewsStory
      WHERE DateTimePosted BETWEEN #PERIOD_START# AND #PERIOD_END# 
      	AND Author = '#URL.Author#'
   </CFQUERY>
 </cfif>
 
   <cfchartdata item="#TimeFormat(PERIOD_START, "short")#" value="#NumberFormat(Val(DownloadInfo.recordcount),"0.00")#">
 
</CFLOOP>
 
    </cfchartseries>
</cfchart>

Open in new window

Avatar of Zvonko
Zvonko
Flag of North Macedonia image

The script seams to be generated by me.
Change please the cfchartdata statement to this:
<cfchartdata item="#LSTimeFormat(PERIOD_START, "short")#" value="#NumberFormat(Val(DownloadInfo.recordcount),"0.00")#">

Open in new window

By the ay, what format is URL.DATE?
ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of benthompson22
benthompson22

ASKER

Thanks for your help! The field in my database for DateTimePosted was a text field and not a Date/Time field so it was storing all the entries in a 12 hour format, not a 24 hour format!

Thanks for you help again!

Ben