0

I create table for hour

CREATE TABLE hour (
    Name1 varchar(25) not null,
    Datee Datetime not null DEFAULT (CURRENT_TIMESTAMP()),
    Monthh date not null DEFAULT (MONTH(CURRENT_DATE()))
);

Mysql only give me 0000-00-00 not Name where i use button in php. What is wrong with this and how correct? In my opinion my phpadmin dont have a MONTH function

Slava Rozhnev
  • 9,510
  • 6
  • 23
  • 39
ExoD
  • 3
  • 2

2 Answers2

0
CREATE TABLE hour ( Name1 varchar(25) not null,
                    Datee DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
                    Monthh TINYINT NOT NULL DEFAULT (MONTH(CURRENT_TIMESTAMP))
                  );

fiddle

PS. HOUR is Reserved word - I'd recommend to rename a table.

Akina
  • 39,301
  • 5
  • 14
  • 25
0

Store full timestamp and it's month part in separate columns in same table is absolutely redundant. You can story only datetime and get it's month in select query:

CREATE TABLE Godzina (
  Nazwa varchar(25) not null,
  Randka Datetime not null DEFAULT CURRENT_TIMESTAMP()
);

INSERT INTO Godzina (Nazwa) VALUES ('TestName');

SELECT 
    Nazwa,
    Randka,
    MONTH(Randka) AS Miesiac
FROM Godzina;

Test it on SQLize.online

Slava Rozhnev
  • 9,510
  • 6
  • 23
  • 39
  • Nothing prevents `Datee` in OP's structure to be changed in future whereas `Monthh` stay unchanged. Your solution is not applicable in such case. – Akina Nov 05 '20 at 12:08