Jump to content


Photo

using dates in days, months, years...


  • Please log in to reply
3 replies to this topic

#1 gabs

gabs
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 11 July 2006 - 10:40 AM

Hi, I would be grateful if somone can point me in the right direction here...I am querying a data base and want to get dates between a start date ($sdate) and end date ($edate).. then if there is more than 60 entries..i want to use every 30th entry ( so that I effectively use months) if it there is more than 730 entries (2 years) I want to use every 365th entry ( so that I  use years effectively) i can't get the code to use and are not even sure how it is suppose to look like, I would be grateful if someone can help me here...

$query = "SELECT date, CONVERT(varchar(12), date, 111) AS 'converted' FROM Enquiries  WHERE date BETWEEN '".$sdate."' AND '".$edate."'";

	$result = odbc_exec($conn, $query) or die (odbc_error());
	while ($row = odbc_fetch_object($result)){
	
	array_push($day, $row->converted);
	$dates = array_unique($day);
	
		$amountdays = count($dates);
			
		if ($amountdays >= 730) {
		
		for( $i = 0 ; $i < $amountdays ; $i += 365 ){ 
		array_push($array_y, $dates[$i]);
		}
		
		} else if (($amountdays < 730) && ($amountdays > 60)) {
		
		
		for( $i = 0 ; $i <  $amountdays  ; $i+= 30
		array_push($array_y, $dates[$i]);
		}
		
		} else {
		$array_y = $dates;
		}
		
		}


#2 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 11 July 2006 - 11:57 AM

is this mysql?
Life's too short for arguing.

#3 gabs

gabs
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 11 July 2006 - 02:00 PM

It is a SQL server using an ODBC driver...but don't let that put you off it works exactly the same..


#4 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 11 July 2006 - 02:07 PM

gabs, good to know that.

well, i don't understand EXACTLY what you wanted to do, but I think you will need these:

to find out how many entries:
select count(*) from table where ....

to select entry 30th:
select * from table where .... limit (29,1)
above statement skip first 29 entry and return only entry 30th.

same goes with 365th entry.

using between is correct.

So, yeah, try to put them together and see what happens.





Life's too short for arguing.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users