Getting a specific string depending on a date variable?

I have 7 columns that contain closing time information, each for one day. (It is similar to VENUE_CLOSE_T_MO, VENUE_CLOSE_T_TU ... etc.)

How can I select one of these columns depending on a date variable ($ somevariable) that contains a specific date?

For example, if date was Sunday, March 18th 22:00, it will select the VENUE_CLOSE_T_SU column.

Thanks for helping everyone!

EDIT (solution given by TEEZ that solved the problem)

My date variable is $ Start .

And this is the code:

$day_name=strtoupper(date('D',$start));
$day_name=substr($day_name,0,2);
$selectcolumn='VENUE_CLOSE_T_'.$day_name;

      

So in this case $ selectcolumn = VENUE_CLOSE_T_SU

And the echo will then be:

$row[$selectcolumn]

      

Thanks for your help again Teez!

+3


source to share


1 answer


first get the name of the day from a variable ($somevariable)

$day_name=strtoupper(date('D',$somevariable));

      

then make a query like below to get the column according to the day in $ somevariable

select concat('VENUE_CLOSE_T_',left($day_name,2)) as datecolumnname  from tableame

      



EDIT:

OR

you don't need to do this in the query if you take the entire column in the query. just add these lines to php code where you are printing data in "Date in Date Column"

$day_name=strtoupper(date('D',$somevariable));
$day_name=substr($day_name,0,2);
$selectcolumn='venues.VENUE_CLOSE_T_'.$day_name; 
echo $row[$selectcolumn];

      

+5


source







All Articles