Reputation: 357
Here, I am using datepicker for inserting date. I have defined datatype for date is like,
field name : date
datatype : datetime
default : As defined 0000-00-00 00:00:00
When I am going to insert the values, but I am not inserting this date
field.
So, it gives me like 1970-01-01 00:00:00
.
I want to add as 0000-00-00 00:00:00
if I not insert the date.
What should I have to do?
Upvotes: 0
Views: 1279
Reputation: 2090
You can do this like Change your column datatype
to TIMESTAMP
DROP TABLE mytablexxx;
CREATE TABLE mytablexxx (
mydate TIMESTAMP DEFAULT '0000-00-00 00:00:00')
INSERT INTO mytablexxx
VALUES();
SELECT * FROM mytablexxx;
// O/p - 0000-00-00 00:00:00
And I think Yours is also working with DATETIME
.
DROP TABLE IF EXISTS mytablexxx;
CREATE TABLE mytablexxx (
mydate DATETIME DEFAULT 0,
mycolumn VARCHAR(36)
);
INSERT INTO mytablexxx(mycolumn) VALUES(UUID());
INSERT INTO mytablexxx(mycolumn) VALUES(UUID());
INSERT INTO mytablexxx(mycolumn) VALUES(UUID());
SELECT * FROM mytablexxx;
// O/p - 0000-00-00 00:00:00
To select Date only
SELECT DATE(mydate) from tableName
You can check functions like DATE()
, DAY()
, YEAR()
, MONTH()
Upvotes: 1
Reputation: 2449
CREATE TABLE IF NOT EXISTS `datet` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`dob` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`name` varchar(24) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Then run like INSERT INTO datet (name) values ('King')
Then check your table
Upvotes: 0