Jump to content

Archived

This topic is now archived and is closed to further replies.

gabs

using dates in days, months, years...

Recommended Posts

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...

[code]$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;
}

}[/code]

Share this post


Link to post
Share on other sites
is this mysql?

Share this post


Link to post
Share on other sites
It is a SQL server using an ODBC driver...but don't let that put you off it works exactly the same..

Share this post


Link to post
Share on other sites
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.




Share this post


Link to post
Share on other sites

×

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.