How t get correct dates to appear each month?

Hello my first post here ,
i m having issue to show correct date to user:
User has activity periods:
2016-11-08 2016-12-07
2016-12-08 2016-12-31
2017-01-01 NULL(yet)
In this case user should show 2016-11-08 on each month

but here
2016-11-08 2016-12-07
2016-12-08 2016-12-31
2017-02-01 NULL(yet)

until December 2016-11-08 - 2016-12-31 , on January nothing and on February 2017-02-01
how to achieve this?

And this is what i have:

	$result_sdl = mysqli_query($conn,"	
	FROM userActive 
	WHERE ('".date('Y-m',strtotime($date))."' >= DATE_FORMAT(`dateFrom`,'%Y-%m')) AND(DATE_FORMAT(`dateTo`,'%Y-%m')>='".date('Y-m',strtotime($date))."' OR dateTo is null) 	
	ORDER BY dateFrom DESC") or die(mysqli_error($conn));
	if (mysqli_num_rows($result_sdl)>0){
		while($row_sdl = mysqli_fetch_array($result_sdl)){

Can you post a sample of the data in the table to make it a bit clearer what the problem is?

what info is needed?Its all about dates from and dates to

I couldn’t really see what you were asking, and figured that the display you showed was the result of the section of code that you posted. I was trying to get an idea of how the code relates to the display. I’m missing something.

Hi fumeepic welcome to the forum

Sorry, but I’m not all that clear about what you’re asking either.

One thing I’m not understanding is why the date formatting is in the WHERE. Typically I would do that either in the SELECT or with PHP

That is, I would let the database compare the.datetime values as they are in the database, and either have the query return them in “human friendly” formatted values or return the datetime and use PHP to format them.

Anyway, are you looking for some type of a GROUP BY?
Does dateFrom ever have future dates?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.