Hello
I have a mysql table with 2 columns, Id and date. How can I insert one more
Column "dayname" that will be filled through sql query with day names related to
The value in the column "date".
Thanks
Hello
I have a mysql table with 2 columns, Id and date. How can I insert one more
Column "dayname" that will be filled through sql query with day names related to
The value in the column "date".
Thanks
was on the right track: weekday names are derived values, not a built‑in column type. There is no "DAYNAME" column type in MySQL. For most cases it is better to keep the original DATE column and derive the day name when you read the data (so you never have redundant, out‑of‑sync values).
If you need the name stored and kept automatically by the server (for indexing or avoiding repeated computation), use a generated column (MySQL 5.7+), or on older servers maintain the value with triggers. Example of adding a stored generated column:
ALTER TABLE your_table
ADD COLUMN dayname VARCHAR(9) AS (DAYNAME(`date`)) STORED; Notes and cautions: storing the textual weekday duplicates data and can cause inconsistencies if updates are mishandled; prefer storing a numeric weekday (TINYINT) if you need a compact, locale‑neutral value and map names in the application. Also be aware that weekday names depend on server locale settings (lc_time_names) and that DATE vs DATETIME/timezone handling can change which weekday you get. For details on automatic/generated columns see the MySQL manual on generated columns: .
Jump to Post— pritaeas 2,276There's no need, check the DAYNAME function.
So if a column type is DAYNAME it will automatically do it.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.