Jump to content

[SOLVED] Need help with time and date functions


newbie69

Recommended Posts

As u can guess i'm a junior at php and there a issue with a sites thats really troubling me.

 

Please visit www.optinum.co.za to get a idea.

 

Please have a look at the right hand column where it says "Next webnar". Its list november 13 as the next webinar. This is fine. All the data for this gets read from a data file.

 

And example of the data file:

--------------------

2007-10-30 Understand the difference between process flows

2007-11-01 image processing with Matlab

2007-11-13 MATLAB Fundamentals and Programming Techniques

-contains other dates----

-----------------------

 

This way the script was supposed work :

Read in the dates and event.

Display the upcoming events.

Dont display events in the past.

 

The scripts does all of this well but, if I have an event thats today eg 2007-11-01,

the site does not display the event on the day of the event. I want it to display the event on the day of the event.

 

Right now on the site it was supposed to display the event 2007-11-01 but it doesnt.

 

I hope i'm being clear :)

 

below i have highlighted when i think the problem maybe. If someone can help me clarify this it would be greatly appreciated

 

this is the snippet of code that controls that:

 

//BUILD THE WEBINARS DATA
case "webinars":
//--- this whole case was changed by Peter Gatlik on 5 June 2007

	echo "<table border=\"0\" cellpadding=\"0\" cellpadding=\"0\">\n";
		//6/08/07 clients did not want to print table headings so tr commented out
	//echo "<tr>";
	//$headers = str_replace("\"", "", $headers);
	//echo "<td class=\"header\">".$headers[0]."</td>";
	//echo "<td class=\"header bordersolid\">".$headers[2]."</td>";
	//echo "</tr>";

	if($numDisplayRecords !== 0) {
		$numlines = $numDisplayRecords;
	}

	//--- Code added by Peter Gatlik 5 June 2007
	$SortingARY = array ();
	if (is_array ($lines)) {
		for ($i = 1; $i < count ($lines); $i++) {
			$Entry = explode ($sep, $lines[$i]);

			if ($Entry[0] == "") {
				continue;
			}

			unset ($DateTemp);
			//--- format for Webinars.txt is 2007-05-20 for example
			$DateTemp = explode ("-", $Entry[0]);
			$TmpYear = $DateTemp[0];
			$TmpMonth = $DateTemp[1];
			if ($TmpMonth < 10) {
				$TmpMonth = "0".((int)$TmpMonth);
			}

			$TmpDay = $DateTemp[2];

			if ($TmpDay < 10) {
				$TmpDay = "0".((int)$TmpDay);
			}


			if (in_array ($TmpDay, array ("", "00")) || in_array ($TmpMonth, array ("", "00")) || in_array ($TmpYear, array ("", "00"))) {
				continue;
			}
			[color=green]

			//--- exlude it if it's in the past
			if (time () > mktime (0, 0, 0, $TmpMonth, $TmpDay, $TmpYear)) {
				continue;
			}[/color]

			//--- create the array index to create the new array
			$Key = $TmpYear.$TmpMonth.$TmpDay;
			$Entry['DisplayDate'] = date ("d F Y", mktime(0,0,0, $TmpMonth, $TmpDay, $TmpYear));
			$SortingARY[$Key][] = $Entry;
		}

		//--- by this point we have the array with keys using the date in Ymd form and we need to sort the array by key and then loop through and create one array
		$FinalARY = array ();
		ksort ($SortingARY);
		reset ($SortingARY);
		foreach ($SortingARY AS $Entries) {
			foreach ($Entries AS $Entry) {
				$FinalARY[] = $Entry;
			}
		}
	}

	for ($i = 0; $i < ($numlines - 1); $i++) {
		$Entry = $FinalARY[$i];
		$Entry = str_replace ("\"", "", $Entry);
		if ($Entry['DisplayDate'] == "") {
			continue;
		}
		echo "<tr>";
		echo "<td class=\"content\">".$Entry['DisplayDate']." </td>\n";
		echo "<td class=\"content bordersolid\">".($Entry[2] == "" ? " " : "<a href=\"".$Entry[4]."\" title=\"".$Entry[2]."\" target=\"_blank\">".$Entry[2]."</a>")."</td>";

		echo "</tr>\n";
	}
	echo "</table>\n";
break;

EDIT: Please use the [code][/code] tags when pasting code on the forums.

Link to comment
Share on other sites

  • 2 months later...

i  have a problem in a sorting a date... first of all the date is in the text format.. the actual sort of the date is 14-APR-07, so how should i do to solved this problem...the display is on the php coding. so i have manage to list out the data but dont have the sequal of month itself...thank you

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.