Hello my first post here ,
i m having issue to show correct date to user:
User has activity periods:
FROM____TO
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
FROM____TO
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,"
SELECT *
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)){
$user_sdl[$row_sdl['userCode']]='y';
$user_sdl_from[$row_sdl['userCode']]=$row_sdl['dateFrom'];
$user_sdl_to[$row_sdl['userCode']]=$row_sdl['dateTo'];
}
}
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.
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?