Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7779207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:35:31+00:00 2026-06-01T18:35:31+00:00

I have an input for date. The format is YYYY-MM-DD . However, MM and

  • 0

I have an input for date. The format is YYYY-MM-DD. However, MM and DD are optional. All the following constitute for expected format:

  • 2012-10-13
  • 2012-09
  • 2010

I need to store this data in MySQL database. It is going to be used for both: to display date and to filter (query) results.

What is the way to do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:35:33+00:00Added an answer on June 1, 2026 at 6:35 pm

    Simply set the month/day to 00 in a DATETIME column. For example:

    2012-04-06
    2012-04-00
    2012-00-00
    

    All of those examples are perfectly valid in DATETIME columns. As working proof, we (the company I work for) use this to specify book’s published dates for our website. We’re currently on MySQL 5.1.54.

    Note: Depending on the language used to format dates (if any), you may need to format them differently depending on whether day/month is provided. For example, in PHP, I needed to check if the day was provided, and manually change the last ‘-00’ to ‘-01’, and then format the date appropriately (leaving out the day in the final result).

    From the Manual (source)

    Thanks to @jon for tracking this down:

    MySQL permits you to store dates where the day or month and day are zero in a DATE or DATETIME column. This is extremely useful for applications that need to store birthdates for which you may not know the exact date. In this case, you simply store the date as ‘2009-00-00’ or ‘2009-01-00’. If you store dates such as these, you should not expect to get correct results for functions such as DATE_SUB() or DATE_ADD() that require complete dates. To disallow zero month or day parts in dates, enable the NO_ZERO_IN_DATE SQL mode.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have the following date as String format. Input 2010-04-20 05:34:58.0 Output I
Input Date Format DD-MM-YYYY Example 15-01-2012 I have a booking date stored in Session
I have input date in following format (mm - dd - yyyy) and i
I have a asp.net page with Date input. It accepts date in the format
I have an input that holds a date value like so 03/15/2012 I am
I have the following date stored as a string 04.09.2009 (dd.mm.yyyy) Now I would
I have a string in the following format. 07/06/2011 5:06 mm/dd/yyyy hh:mm am using
i have a date/time field called MyDate. Originally, its format is mm/dd/yyyy and there
I have a date in this format 10/12/2011 12:55:00 PM (MM-DD-YYYY time) I would
In my web application, I have users input a date in a simple textbox.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.