Jump to content


Photo

need help with date()


  • Please log in to reply
3 replies to this topic

#1 komquat

komquat
  • Members
  • PipPipPip
  • Advanced Member
  • 130 posts
  • LocationHoughton, MI

Posted 12 October 2006 - 02:05 PM

I am looking to highlight one line from the information I pull from a DB.

The current format of the DB is 2006-02-19

I want to have a list of all dates and highlight the next one in the sequence according to today. 

Ex

Week Date Race Track
19. 2006-07-16 New England 300 New Hampshire International Sp
20. 2006-07-23 Pennsylvania 500 Pocono Raceway
21. 2008-06-06 Allstate 400 at the Brickyard Indianapolis Motor Speedway
22. 2006-08-13 Sirius Satellite Radio Watkins Glen International
23. 2006-08-20 GFS Marketplace 400 Michigan International Speedwa
24. 2006-08-26 Sharpie 500 Bristol Motor Speedway
25. 2006-09-03 Sony HD 500 California Speedway
26. 2006-09-09 Chevy Rock & Roll 400 Richmond International Raceway
27. 2006-09-17 Sylvania 300 New Hampshire International Sp
28. 2006-09-24 Dover 400 Dover International Speedway
29. 2006-10-01 Banquet 400 presented by ConAg Kansas Speedway
30. 2006-10-08 UAW-Ford 500 Talladega Superspeedway
31. 2006-10-14 Bank of America 500 Lowe's Motor Speedway
32. 2006-10-22 Subway 500 Martinsville Speedway
33. 2006-10-29 Bass Pro Shops MBNA 500 Atlanta Motor Speedway
34. 2006-11-05 Dickies 500 Texas Motor Speedway
35. 2006-11-12 Checker Auto Parts 500 Phoenix International Raceway
36. 2006-11-19 Ford 400 Homestead-Miami Speedway


I want line 31 highlighted and the rest in normal text. 

Please help

thanks in advance

#2 komquat

komquat
  • Members
  • PipPipPip
  • Advanced Member
  • 130 posts
  • LocationHoughton, MI

Posted 13 October 2006 - 02:57 PM

Anyone good with dates and things, please give a hand.

Thanks in advance

#3 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 13 October 2006 - 03:22 PM

Hey... what you want is to turn the timestamp into a unix timestamp like so:

<?php

function getTimeStamp($date) {
	// 2006-05-10 00:00:00
	// 0123456789012345678
	return mktime(	substr($date, 11, 2),	// Hours
				substr($date, 14, 2),	// Minutes
				substr($date, 17, 2),	// Seconds
				substr($date, 5, 2),	// Months
				substr($date, 8, 2),	// Days
				substr($date, 0, 4));	// Years
}

?>

To look something like this

<?php

$highlighted = false;
foreach ($events as $event) {
	echo $event["id"] .". ";
	if (!$highlighted && time() < getTimeStamp($event["time"])) {
		echo "<span style='color: #990099;'>". $event["time"] ."</span>";
		$highlight = true;
	} else {
		echo $event["time"];
	}

	echo $event["otherdata"];
}

?>

SA PHP Archives - www.phparchives.za.org

#4 komquat

komquat
  • Members
  • PipPipPip
  • Advanced Member
  • 130 posts
  • LocationHoughton, MI

Posted 19 October 2006 - 10:35 PM

If anyone is interested, I figured it out with MySQL!

Here is the code:
$sql_next = "SELECT sched_id, race_date, track, race, (day(curdate()))-(day(race_date)) as diff 
	FROM nascar_schedule 
	WHERE month(curdate()) = month(race_date) and day(curdate()) <= day(race_date)	
				and (day(curdate()))-(day(race_date)) >= '-7' 
	ORDER BY sched_id
	";


Week Date Race Track
19. 2006-07-16 New England 300 New Hampshire International Sp
20. 2006-07-23 Pennsylvania 500 Pocono Raceway
21. 2008-06-06 Allstate 400 at the Brickyard Indianapolis Motor Speedway
22. 2006-08-13 Sirius Satellite Radio Watkins Glen International
23. 2006-08-20 GFS Marketplace 400 Michigan International Speedwa
24. 2006-08-26 Sharpie 500 Bristol Motor Speedway
25. 2006-09-03 Sony HD 500 California Speedway
26. 2006-09-09 Chevy Rock & Roll 400 Richmond International Raceway
27. 2006-09-17 Sylvania 300 New Hampshire International Sp
28. 2006-09-24 Dover 400 Dover International Speedway
29. 2006-10-01 Banquet 400 presented by ConAg Kansas Speedway
30. 2006-10-08 UAW-Ford 500 Talladega Superspeedway
31. 2006-10-14 Bank of America 500 Lowe's Motor Speedway
32. 2006-10-22 Subway 500 Martinsville Speedway
33. 2006-10-29 Bass Pro Shops MBNA 500 Atlanta Motor Speedway
34. 2006-11-05 Dickies 500 Texas Motor Speedway
35. 2006-11-12 Checker Auto Parts 500 Phoenix International Raceway
36. 2006-11-19 Ford 400 Homestead-Miami Speedway





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users