Insert date in the database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ankitjain100
    New Member
    • Apr 2010
    • 4

    #1

    Insert date in the database

    Hello Guys,

    This is my first question on this platform.

    I want to ask that How to insert Date in MY SQL in the MM-DD-YY format i am using JSP as my frontend.

    Please tell me , i will be very thankful you all.

    Ankit
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    That's simple: You don't.

    MySQL handles all dates in the same format: 'YYYY-MM-DD'. Internally it is of course stored differently, but this is how MySQL presents dates to you, and how it expects to receive them.

    If you need to get the date in a different format, you do so when you retrieve it. You use the DATE_FORMAT function to re-format the date in your queries.
    [code=sql]SELECT DATE_FORMAT(`my Date`, '%M %D, %Y')
    FROM `myTable`[/code]
    This would return the dates in a format like: 'April 8th, 2010'.
    (See the link above for the correct elements to construct the format you need.)

    Comment

    • ankitjain100
      New Member
      • Apr 2010
      • 4

      #3
      Thanks Atli, very very thank you for give me a perfect answer, now i have solved my problem.

      regards
      Ankit Jain

      Comment

      Working...