Store incomplete date in MySQL date field

前端 未结 3 1442
孤街浪徒
孤街浪徒 2020-12-28 16:13

I want to offer the user the possibility to introduce dates that are incomplete (for example just the year 2005, or Jan 1998) but also complete dates with year, month, day.

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-28 16:33

    Well, if you used a date field then you should expect those 0s. One way you can get rid of them is by using the varchar selection rather. However, it is better to use a date field since thats what is stored there.

    If you have to allow users to enter an incomplete date then it has to be a varchar and in that case you can format the input with your script and store in that column

提交回复
热议问题