Viewing Individual Entry / Main
  ::   September 28, 2002

Working with Date Values on the Y-Axis in CFCHART
I've seen a few posts from developers on the Macromedia Forums lately complaining that they can't get CFCHART to display dates on the y-axis. Since I'm finishing up the CFCHART chapter of my book right now, I decided to look into this. It turns out, that this functionality is not at all documented in any of the Macromedia documentation, nor anywhere else that I can tell. After spending a few hours trying to figure out what CFCHART could possibly want as it's date values, I finally figured it out. For some reason, you can't pass dates in formats like mm/dd/yyyy. My next thought was to try a numeric format, so I tried CF MX's new getNumericDate() funciton. That didn't work. Next, I thought of using Epoch seconds. I tried a random Epoch time, but the date CF showed in the chart was about 32 years off! After more messing around, I finally hit on the solution. You need to take your date, convert it to Epoch seconds adjusted for your UTC offset, and multiply that number by 1000. I'm not sure why you have to multiply by 1000. The only thing I can think of is that the 1000 represents milliseconds tacked on to the date. Go figure.

So, here's some code that illustrates how to make it all work:

/** * Returns the number of seconds since January 1, 1970, 00:00:00 (Epoch time). * * @param DateTime Date/time object you want converted to Epoch time. (Required) * @return Returns a numeric value. * @author Rob Brooks-Bilson (rbils@amkor.com) * @version 1, June 21, 2002 */ function GetEpochTimeFromLocal() { var datetime = 0; if (ArrayLen(Arguments) eq 0) { datetime = Now(); } else { datetime = arguments[1]; } return DateDiff("s", DateConvert("utc2Local", "January 1 1970 00:00"), datetime); }

/** * Returns the number of seconds since January 1, 1970, 00:00:00 * * @param DateTime Date/time object you want converted to Epoch time. * @return Returns a numeric value. * @author Chris Mellon (mellan@mnr.org) * @version 1, February 21, 2002 */ function GetEpochTime() { var datetime = 0; if (ArrayLen(Arguments) is 0) { datetime = Now();

} else { if (IsDate(Arguments[1])) { datetime = Arguments[1]; } else { return NULL; } } return DateDiff("s", "January 1 1970 00:00", datetime); }



Calendar
Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            

Recommended Reading
Ishmael: An Adventure of the Mind and Spirit

Archives by Subject
Announcements (28)
ColdFusion (61)
Database (12)
Dreamweaver (1)
Flash (2)
Flash Remoting (2)
Flex (3)
General Development (2)
Homesite + (1)
Mach-II (3)
MAX (9)
Mozilla (2)
Music (1)
Politics (1)
Portals (2)
Travel (2)

Search

Links
CFLib.org
Raymond Camden's Blog
Christian Cantrell's Blog
Sean Corfield's Blog
Nathan Dintenfass' Blog
Todd Rafferty's Blog
Steve Rittler's Blog
Cameron Childress's Blog

Credits
Based on blog.cfc by Raymond Camden

XML Feed