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:



So in this case $ selectcolumn = VENUE_CLOSE_T_SU

And the echo will then be:



Thanks for your help again Teez!


source to share

1 answer

first get the name of the day from a variable ($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




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"

echo $row[$selectcolumn];




All Articles