lot lot - 10 months ago 24
SQL Question

Is there a way to automatically update a value based on the date?

I have a table with two columns,

(datetime) and

The user can give in this date at any given time. Is there a way to automatically update
is less than today's date? A script or something? Thanks!


I would suggest that you use a view:

create view v_table as
    select t.*,
           (startdate <= curdate() then 1 else 0 end) as has_started
    from table t;

If you query the view, the has_started column will be updated when accessed. The value doesn't need to be stored in the database.

(Note: if there is a time component, you can use now() instead of curdate().)