Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

JQuery.get() function returning undefined

Avatar of jweav1
jweav1 asked on
4 Comments1 Solution1785 ViewsLast Modified:
I am pulling data from twitter and need to compare the date a tweet was originated to the current date.

Twitter returns a created_at item in its JSON response which is formatted as
"Fri, 02 Jul 2010 14:03:33 +0000"  
So to make the date comparison I am pulling each date and sending it to a strtotime php function which converts it to a timestamp which can be easily compared to a timestamp of the current date.

I am sending each date individually from the JSON array because it would be to big and cumbersome to send them all attached to the URL.

This all works fine and the times are being converted.

The problem is: my convertDates function is supposed to return the converted tweetDate and load it into the converetedDates array, but the function keeps returning undefined.

I've logged the convertDates function output right before it returns and it is showing the correct timestamp output, but something is happening when it returns.

The code is attached.

Thanks in advance.

$(document).ready(function () {	
	 var date;
	 var convertedDates = [];
	 var theTweets;

	function convertDates(dates){ 
		$.get('convert_dates.php', {
			dates: dates
			}, function (response) {
				tweetDate = response.date;
				return tweetDate;
			}, 'json');
      url: 'http://search.twitter.com/search.json?rpp=50q=happy',
	 dataType: 'jsonp',
	success: function (data) {
		theTweets = data.results;
	        for (i=0; i<theTweets.length; i++){
		     date = theTweets[i].created_at;
		     convertedDates[i] = convertDates(date);

just in case here is the php for convert_dates.php:


$dates = $_GET['dates'];

function convertDates($dates){

$length = count($dates);

$newDates = array();

for ($x=0; $x<$length; $x++) {
	$newDates[date] = strtotime($dates[$x]);

return $newDates;


$result = convertDates($dates);

echo json_encode($result);

Avatar of leakim971
leakim971Flag of Guadeloupe imageMultitechnician
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answers