ok so i am working on a program that has a table of all the presidents and info on each of them. i tried to insert the date of their birthdays and deaths, but just got 0000-00-00 for a result when i went to see what the outcome looked like. help please

this is what i did to input it in.

INSERT INTO president_info (id, name, mname, last, bdate, ddate, yr_sworn, yr_left, party, home_town, state,vp) VALUES (1, 'George', 'n/a', 'Washington', 1732-02-22, 1799-12-14, 1789, 1796, 'Federalist', 'Westmoreland', 'Virginia', 'John Adams');
SELECT * FROM president_info;

+----+--------+-------+------------+------------+------------+----------+---------+-----------+--------------+----------+------------+
| id | name | mname | last | bdate | ddate | yr_sworn | yr_left | party | home_town | state | vp |
+----+--------+-------+------------+------------+------------+----------+---------+-----------+--------------+----------+------------+
| 1 | George | n/a | Washington | 0000-00-00 | 0000-00-00 | 0000 | 0000 | Federalist | Westmoreland | Virginia | John Adams |
+----+--------+-------+------------+------------+------------+----------+---------+-----------+--------------+----------+------------+
1 row in set (0.00 sec)

Dani AI

Generated

ended up with a zero date (MySQL shows it as 0000-00-00) — that means MySQL could not convert the supplied value into a valid DATE for that column. The usual causes are: unquoted date literals being evaluated as arithmetic, inserting into a column type that cannot store the year range used (for example TIMESTAMP or YEAR), or invalid-format strings when SQL mode allows silent conversion to the zero date. asked for the fix; here is a short checklist and practical guidance.

Check the schema and SQL mode first:

SHOW CREATE TABLE president_info;
DESCRIBE president_info;
SELECT @@sql_mode;
SHOW WARNINGS;

If the date column is TIMESTAMP or YEAR, those types have limited ranges (TIMESTAMP historically ~1970–2038; YEAR has its own restricted range). DATE/DATETIME accept a much wider historical range. If you need pre-20th-century dates, use DATE or DATETIME (ALTER TABLE ... MODIFY ...). Always insert literal dates as quoted YYYY-MM-DD strings or parse strings with STR_TO_DATE() rather than leaving them unquoted.

Example insertion patterns (replace placeholders as needed):

INSERT INTO president_info (bdate, ddate) VALUES ('YYYY-MM-DD', 'YYYY-MM-DD');

INSERT INTO president_info (bdate) VALUES (STR_TO_DATE('DD/MM/YYYY', '%d/%m/%Y'));

For authoritative limits and behavior of the MySQL date/time types, see the MySQL manual: MySQL date and time types.

I see you already marked thread as solved. Did you get your solution? If so would you mind to share it with others?

well i solved the problem. i am not able to use the date function because the years i am using are before 1900s. you can only use the date when its between 1900 - 2036 or something similar to it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.