Coverting Date Format mm/dd/yy to yyyy-mm-dd To Insert into MySQL

Posted on 2006-06-07
Last Modified: 2007-12-19
I recently got some help converting Dates to display as yyyy-mm-dd to keep consistent with the MySQL format.  Unfortunately I now need to reverse that it so the Dates display as the default mm/dd/yy, but convert when the form is submitted to yyyy-mm-dd for proper insertion into the database.  If someone could offerhelp with that code I would appreciate it.  Thanks.
Question by:blob150
    LVL 75

    Expert Comment

    by:Anthony Perkins
    If you cannot use the FormatDate function consider something like this function:

    Function Date2YMD (ByVal Dat)

    Date2YMD = CStr(Year(Dat)) & "-" & Right("0" & CStr(Month(Dat)), 2) "-" & Right("0" & CStr(Day(Dat)), 2)

    End Function
    LVL 75

    Expert Comment

    by:Anthony Perkins
    Oops, typo:

    Function Date2YMD (ByVal Dat)

    Date2YMD = CStr(Year(Dat)) & "-" & Right("0" & CStr(Month(Dat)), 2) & "-" & Right("0" & CStr(Day(Dat)), 2)

    End Function

    Author Comment

    Thanks for the reply.  I can get the function to display the dates as yyyy-mm-dd when the page loads, but I need the dates to display as mm/dd/yy and convert to yyyy-mm-dd only after the form is submitted.  How can I do that?
    LVL 31

    Accepted Solution

    You just store each format in 2 different variables.  ONe variable has one format....the other variable has the other format.  Then use them as you need them.

    You have all the information you need for your previous questions...

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
    Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now