Jump to content

using dates in days, months, years...


gabs

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]
Link to comment
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.




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.