0

I have a database table--> date field and the date format is yyyy-mm-dd

if i input in anouther format then field show 0000-00-00

what is the problem and how i can overcome this whereas i have use no form encode method??

2 Answers 2

1

I would recommend using int(32) for your date field and storing unixtime. That way you can format your date into any type of string you want to display.

UNIX_TIMESTAMP()

It's called and the you can do this in your query.

INSERT INTO `table` (`date`) VALUES (UNIX_TIMESTAMP());

You can parse unixtime in any language, and many (like PHP) have built it parsing of unixtime.

date("Y-m-d", $row["time"]); // YYYY-MM-DD
Sign up to request clarification or add additional context in comments.

1 Comment

This also makes it easier for date calculations (ie if($date1 < $date2) { print "date1 was before date2!"} );
1

Insert dates in YYYY-MM-DD (ISO format) and when retrieving the date, you may convert it to any format you like using:

DATE_FORMAT()

Reference:

DATE_FORMAT(date,format).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.