0

I'm using fusion charts. I'm trying to attach elements of an SQL array onto a Javascript strURL so they can be passed to another page. Fields such as siteid and name get passed fine but whenever I try to pass over the timestamp it fails to load the graph. I can't explain the whole thing in full as there are too many parts to write about but if anyone has any ideas as to why a timestamp cannot be attached to a strURL then I would love to know.

The returned value looks like: 2011-12-19 12:00:00

3
  • I think you're best off doing some debugging and seeing what the content of the field you're trying to pass (the timestamp) really is. Could it be that it's an object? Might you need to cast it to a string? console.log() and your in browser debugger is your friend :) Commented Jan 4, 2012 at 18:03
  • We can probably help if you can show us the timestamp and what the final strURL looks like after you've tried to attach these variables to it. Commented Jan 4, 2012 at 18:07
  • Thanks, i've edited the post to show the timestamp that i get back from the database. I've narrowed it down to be the timestamp because other fields can get passed through the javascript, only the time field fails. Commented Jan 5, 2012 at 9:51

1 Answer 1

2

The problem probably is caused by the form of the timestamp. If it contains special characters that are not encoded properly, then you have a problem.

Get Unix epoch from database

You can avoid this by getting Unix epoch timestamp directly from database like that (example for MySQL):

SELECT UNIX_TIMESTAMP(`my_timestamp`) FROM `my_table`;

and because such timestamp should only consist of digits, you should not have any problems regarding incorrect characters.

Process Unix epoch in JavaScript correctly

Processing Unix epoch timestamps in JavaScript is rather simple:

var db_timestamp = '1330655412';
var my_time = new Date();
my_time.setTime(db_timestamp * 1000);

See this jsfiddle for a proof.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.